Python scipy.newaxis() Examples
The following are 9
code examples of scipy.newaxis().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy
, or try the search function
.
Example #1
Source File: recipe-576547.py From code with MIT License | 6 votes |
def coupling_optim_garrick(y,t): creation=s.zeros(n_bin) destruction=s.zeros(n_bin) #now I try to rewrite this in a more optimized way destruction = -s.dot(s.transpose(kernel),y)*y #much more concise way to express\ #the destruction of k-mers for k in xrange(n_bin): kyn = (kernel*f_garrick[:,:,k])*y[:,s.newaxis]*y[s.newaxis,:] creation[k] = s.sum(kyn) creation=0.5*creation out=creation+destruction return out #Now I work with the function for espressing smoluchowski equation when a uniform grid is used
Example #2
Source File: recipe-576547.py From code with MIT License | 6 votes |
def coupling_optim(y,t): creation=s.zeros(n_bin) destruction=s.zeros(n_bin) #now I try to rewrite this in a more optimized way destruction = -s.dot(s.transpose(kernel),y)*y #much more concise way to express\ #the destruction of k-mers kyn = kernel*y[:,s.newaxis]*y[s.newaxis,:] for k in xrange(n_bin): creation[k] = s.sum(kyn[s.arange(k),k-s.arange(k)-1]) creation=0.5*creation out=creation+destruction return out #Now I go for the optimal optimization of the chi_{i,j,k} coefficients used by Garrick for # dealing with a non-uniform grid.
Example #3
Source File: collect_counts_incrementally.py From pancanatlas_code_public with MIT License | 6 votes |
def appendToHDF5(file, data, name): ### get current shape tmp = file[name].shape ### resize if len(tmp) == 1: file[name].resize((tmp[0] + data.shape[0],)) file[name][tmp[0]:] = data elif len(tmp) == 2: file[name].resize((tmp[0], tmp[1] + 1)) if len(data.shape) < 2: file[name][:, tmp[1]:] = data[:, sp.newaxis] else: file[name][:, tmp[1]:] = data else: print >> sys.stderr, "cannot append data to HDF5 with more than 2 dimensions" sys.exit(-1)
Example #4
Source File: histogram.py From brats_segmentation-pytorch with MIT License | 5 votes |
def __quadratic_forms_matrix_euclidean(h1, h2): r""" Compute the bin-similarity matrix for the quadratic form distance measure. The matric :math:`A` for two histograms :math:`H` and :math:`H'` of size :math:`m` and :math:`n` respectively is defined as .. math:: A_{m,n} = 1 - \frac{d_2(H_m, {H'}_n)}{d_{max}} with .. math:: d_{max} = \max_{m,n}d_2(H_m, {H'}_n) See also -------- quadratic_forms """ A = scipy.repeat(h2[:,scipy.newaxis], h1.size, 1) # repeat second array to form a matrix A = scipy.absolute(A - h1) # euclidean distances return 1 - (A / float(A.max())) # //////////////// # # Helper functions # # //////////////// #
Example #5
Source File: recipe-576547.py From code with MIT License | 5 votes |
def Brow_ker_cont_optim(Vlist): kern_mat=2.*k_B*T_0/(3.*mu)*(Vlist[:,s.newaxis]**(1./3.)+\ Vlist[s.newaxis,:]**(1./3.))**2./ \ (Vlist[:,s.newaxis]**(1./3.)*Vlist[s.newaxis,:]**(1./3.)) return kern_mat
Example #6
Source File: recipe-576547.py From code with MIT License | 5 votes |
def mycount_garrick(V): f=s.zeros((n_bin, n_bin, n_bin)) Vsum=V[:,s.newaxis]+V[s.newaxis,:] # matrix with the sum of the volumes in the bins for k in xrange(1,(n_bin-1)): f[:,:,k]=s.where((Vsum<=V[k+1]) & (Vsum>=V[k]), (V[k+1]-Vsum)/(V[k+1]-V[k]),\ f[:,:,k] ) f[:,:,k]=s.where((Vsum<=V[k]) & (Vsum>=V[k-1]),(Vsum-V[k-1])/(V[k]-V[k-1]),\ f[:,:,k]) return f
Example #7
Source File: plot.py From pytorch-asr with GNU General Public License v3.0 | 5 votes |
def plot_llk(train_elbo, test_elbo): import matplotlib.pyplot as plt import scipy as sp import seaborn as sns import pandas as pd plt.figure(figsize=(30, 10)) sns.set_style("whitegrid") data = np.concatenate([np.arange(len(test_elbo))[:, sp.newaxis], -test_elbo[:, sp.newaxis]], axis=1) df = pd.DataFrame(data=data, columns=['Training Epoch', 'Test ELBO']) g = sns.FacetGrid(df, size=10, aspect=1.5) g.map(plt.scatter, "Training Epoch", "Test ELBO") g.map(plt.plot, "Training Epoch", "Test ELBO") plt.savefig(str(Path(result_dir, 'test_elbo_vae.png'))) plt.close('all')
Example #8
Source File: large_sparse_functions.py From megaman with BSD 2-Clause "Simplified" License | 5 votes |
def set_sparse_diag_to_one(mat): # appears to implicitly convert to csr which might be a problem (n, n) = mat.shape # copy the matrix, subtract the diagonal values, add identity matrix # see http://nbviewer.jupyter.org/gist/Midnighter/9992103 for speed testing cpy = mat - dia_matrix((mat.diagonal()[sp.newaxis, :], [0]), shape=(n, n)) + identity(n) return(cpy)
Example #9
Source File: data_parser.py From GPPVAE with Apache License 2.0 | 4 votes |
def read_face_data(h5fn): f = h5py.File(h5fn, "r") keys = ["test", "train", "val"] Y = {} Rid = {} Did = {} for key in keys: Y[key] = f["Y_" + key][:] for key in keys: Rid[key] = f["Rid_" + key][:] for key in keys: Did[key] = f["Did_" + key][:] f.close() # exclude test and validation not in trian uDid = sp.unique(Did["train"]) for key in ["test", "val"]: Iok = sp.in1d(Did[key], uDid) Y[key] = Y[key][Iok] Rid[key] = Rid[key][Iok] Did[key] = Did[key][Iok] # one hot encode donors table = {} for _i, _id in enumerate(uDid): table[_id] = _i D = {} for key in keys: D[key] = sp.array([table[_id] for _id in Did[key]])[:, sp.newaxis] # one hot encode views uRid = sp.unique(sp.concatenate([Rid[key] for key in keys])) table_w = {} for _i, _id in enumerate(uRid): table_w[_id] = _i W = {} for key in keys: W[key] = sp.array([table_w[_id] for _id in Rid[key]])[:, sp.newaxis] for key in keys: Y[key] = Y[key].astype(float) / 255.0 Y[key] = torch.tensor(Y[key].transpose((0, 3, 1, 2)).astype(sp.float32)) D[key] = torch.tensor(D[key].astype(sp.float32)) W[key] = torch.tensor(W[key].astype(sp.float32)) return Y, D, W