当前位置: 首页>>代码示例>>Python>>正文


Python scipy.newaxis方法代码示例

本文整理汇总了Python中scipy.newaxis方法的典型用法代码示例。如果您正苦于以下问题:Python scipy.newaxis方法的具体用法?Python scipy.newaxis怎么用?Python scipy.newaxis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy的用法示例。


在下文中一共展示了scipy.newaxis方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: coupling_optim_garrick

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import newaxis [as 别名]
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 
开发者ID:ActiveState,项目名称:code,代码行数:19,代码来源:recipe-576547.py

示例2: coupling_optim

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import newaxis [as 别名]
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. 
开发者ID:ActiveState,项目名称:code,代码行数:18,代码来源:recipe-576547.py

示例3: appendToHDF5

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import newaxis [as 别名]
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) 
开发者ID:ratschlab,项目名称:pancanatlas_code_public,代码行数:19,代码来源:collect_counts_incrementally.py

示例4: __quadratic_forms_matrix_euclidean

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import newaxis [as 别名]
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 #
# //////////////// # 
开发者ID:doublechenching,项目名称:brats_segmentation-pytorch,代码行数:30,代码来源:histogram.py

示例5: Brow_ker_cont_optim

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import newaxis [as 别名]
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 
开发者ID:ActiveState,项目名称:code,代码行数:7,代码来源:recipe-576547.py

示例6: mycount_garrick

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import newaxis [as 别名]
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 
开发者ID:ActiveState,项目名称:code,代码行数:12,代码来源:recipe-576547.py

示例7: plot_llk

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import newaxis [as 别名]
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') 
开发者ID:jinserk,项目名称:pytorch-asr,代码行数:16,代码来源:plot.py

示例8: set_sparse_diag_to_one

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import newaxis [as 别名]
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) 
开发者ID:mmp2,项目名称:megaman,代码行数:9,代码来源:large_sparse_functions.py

示例9: read_face_data

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import newaxis [as 别名]
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 
开发者ID:fpcasale,项目名称:GPPVAE,代码行数:49,代码来源:data_parser.py


注:本文中的scipy.newaxis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。