查看“Scipy”的源代码
←
Scipy
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
http://www.scipy-lectures.org ==稀疏矩阵== *[https://blog.csdn.net/Sherry_Yue/article/details/102652829] from scipy.sparse import csr_matrix import numpy as np indptr = np.array([0,2,3,6]) #游标指针 数据 = n+1,前面n个分别是各行数据的起点,最后一个是非零数据的总数 第0组(第0行)在 indices / data 中的起始下标[0];1组(第1行)在 indices / data 中的起始下标[2];第2组(第2行)在 indices / data 中的起始下标[3]。 indices = np.array([0,2,2,0,1,2]) #非零数据所在的列 data = np.array([1,2,3,4,5,6]) #非零数据的数值 csr_matrix_0 = csr_matrix((data,indices,indptr),shape=(3,3)) print(csr_matrix_0.toarray()) ==求函数最小值== *Methods based on conjugate gradient are named with ‘cg’ in scipy. The simple conjugate gradient method to minimize a function is scipy.optimize.fmin_cg(): *n scipy, scipy.optimize.fmin() implements the Nelder-Mead approach: (不太依赖于倒数) *Brute force: a grid search :scipy.optimize.brute() evaluates the function on a given grid of parameters and returns the parameters corresponding to the minimum value.The parameters are specified with ranges given to numpy.mgrid. By default, 20 steps are taken in each direction: *Non-linear least squares: Levenberg–Marquardt algorithm implemented in scipy.optimize.leastsq(). *If the function is linear, this is a linear-algebra problem, and should be solved with scipy.linalg.lstsq(). ==文件输出== # Some test data x = np.arange(200).reshape((4,5,10)) # Specify the filename of the .mat file matfile = 'test_mat.mat' # Write the array to the mat file. For this to work, the array must be the value # corresponding to a key name of your choice in a dictionary scipy.io.savemat(matfile, mdict={'out': x}, oned_as='row') # For the above line, I specified the kwarg oned_as since python (2.7 with # numpy 1.6.1) throws a FutureWarning. Here, this isn't really necessary # since oned_as is a kwarg for dealing with 1-D arrays. # Now load in the data from the .mat that was just saved matdata = scipy.io.loadmat(matfile) # And just to check if the data is the same: assert np.all(x == matdata['out'])
返回至“
Scipy
”。
导航菜单
个人工具
登录
命名空间
页面
讨论
大陆简体
已展开
已折叠
查看
阅读
查看源代码
查看历史
更多
已展开
已折叠
搜索
导航
首页
社群首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息