【如何在python / scipy中有效地组装大型稀疏矩阵】教程文章相关的互联网学习教程文章

python – 由scipy中的稀疏矩阵分组并返回一个矩阵【代码】

关于使用具有稀疏矩阵的groupby的SO有几个问题.但是输出似乎是列表,dictionaries,dataframes和其他对象. 我正在研究NLP问题,并希望在处理过程中将所有数据保存在稀疏的scipy矩阵中以防止内存错误. 这是上下文: 我已经矢量化了一些文件(sample data here):import pandas as pd from sklearn.feature_extraction.text import CountVectorizerdf = pd.read_csv('groupbysparsematrix.csv') docs = df['Text'].tolist()vectorizer = ...

如何为python安装numpy和scipy?【代码】

我厌倦了尝试为phyton 2.7.5安装numpy和scipy,我需要这个版本的python,因为我的最终目标是安装类(http://class-code.net/)和montepython(http://montepython.net/). (我有ubuntu 12.04) 当我尝试导入numpy或scipy时,我每次都会收到以下错误:$phyton2.7 >>> import numpy Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <modu...

Python多处理scipy:过多的文件系统’stat’和’open’尝试【代码】

我在Python中观察到一些极端奇怪的行为.请考虑以下代码:from multiprocessing import Process import scipydef test():passfor i in range(1000):p1 = Process(target=test)p1.start()p1.join()print i当我在这上面运行strace -f时,我从循环中得到以下段:clone(Process 19706 attached child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x2b23afde1970) = 19706 [pid 19706] set_robust_l...

python – 如何使用scipy执行亚像素精度的图像互相关

下图显示了两个相同半径的圆,用抗锯齿渲染,只是左圆圈水平移动了一半像素(注意圆圈水平中心位于左边像素的中间,右边的像素边界) ). 如果我执行互相关,我可以在相关数组上取最大值的位置,然后计算移位.但由于像素位置总是整数,我的问题是: “如何在Numpy / Scipy中使用互相关获得两个图像之间的子像素(浮点)偏移?” 在我的脚本中,使用scipy.signal.correlate2d或scipy.ndimage.filters.correlate,它们似乎产生相同的结果. 这里的圆...

python – 最大的特征向量和可能的Scipy古怪【代码】

不确定这是否是包中的错误或由于其他原因,但我们继续. 我正在使用以下包在相似度得分的对称矩阵(大小为1010)上找到最大的特征值及其对应的特征向量:scipy.sparse.linalg.eigen.arpack.eigsh,像这样:scipy.sparse.linalg.eigen.arpack.eigsh(mymatrix, 1, which='LM')现在的问题是,当我运行它几次(使用相同的矩阵,设置等)时,有时特征向量中的值是正的,有时是负的(参见运行3). 有谁知道为什么会这样,或者它是一个错误?似乎没有一种...

python scipy stats帕累托适合:它是如何工作的【代码】

…帮助和在线文档说scipy.stats.pareto.fit函数将变量作为要拟合的数据集的变量,并可选择b(指数),loc,scale.结果是三元组(指数,loc,scale) 从相同分布生成数据应该导致拟合找到用于生成数据的参数,例如, (使用python 3 colsole)$ python Python 3.3.0 (default, Dec 12 2012, 07:43:02) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>>(在下面的代码行中省略了python控制台提示...

python – 是否有可能在scipy.spatial的Delaunay中强制执行边缘(约束delaunay三角剖分)?

我正在试验scipy.spatial’s implementation of Qhull’s Delaunay triangulation. 是否有可能以保留输入顶点定义的边的方式生成三角剖分? (编辑:即受约束的Delaunay三角剖分.)可以使用triangle package for Python. 例如,在下图中,有几个三角形(蓝色)忽略由顶点定义的边缘(红色)的位置.有没有办法强制执行这些边缘,使它们在所有情况下都是三角测量结果的一部分?解决方法:您正在寻找的是constrained Delaunay triangulation,不幸...

python – 有效地改变scipy.spare.csr_matrix的维度[复制]【代码】

参见英文答案 > Adding a column of zeroes to a csr_matrix 2个我有一个函数,它采用csr_matrix并对其进行一些计算. 这些计算的行为要求该矩阵的形状是特定的(比如NxM). 我发送的输入具有较少的列和确切的行数. (例如,它具有形状=(A,B),其中A< N和B == M)例如:我有对象x >>>x = csr_matrix([[1,2],[1,2]]) >>>x (0, 0) 1 (0, 1) 2 (1, 0) 1 (1, 1) 2 >>>x.shape (2, 2)和函数f:def f(csr...

在Python中读取scipy / numpy中的csv文件【代码】

我在python中读取由制表符分隔的csv文件时遇到问题.我使用以下功能:def csv2array(filename, skiprows=0, delimiter='\t', raw_header=False, missing=None, with_header=True):"""Parse a file name into an array. Return the array and additional header lines. By default,parse the header lines into dictionaries, assuming the parameters are numeric,using 'parse_header'."""f = open(filename, 'r')skipped_rows = [...

griddata运行时错误 – Python / SciPy(插值)【代码】

我使用scipy的griddate函数进行插值. 当python执行griddata函数时,以下错误消息意味着什么?File "C:\Python25\lib\site-packages\scipy\interpolate\ndgriddata.py", line 182, in griddata ip = LinearNDInterpolator(points, values, fill_value=fill_value) File "interpnd.pyx", line 192, in interpnd.LinearNDInterpolator.__init__ (scipy\interpolate\interpnd.c:2524) File "qhull.pyx", line 917, in scipy.spatial.qhu...

Python SciPy UnivariateSpline返回NaN – 范围内的值【代码】

我正在尝试使用SciPy的UnivariateSpline来定位曲线上的一个点.不幸的是,我的结果是nan.这是一个最小的例子:from scipy.interpolate import UnivariateSpline spline = UnivariateSpline([0.6, 0.4, 0.2, 0.0], [-0.3, -0.1, 0.1, 0.3], w=None, bbox=[None, None], k=1, s=0) POINT = spline([0.15]) print POINT 结果是[NaN].我想念UnivariateSpline的哪个功能? 我正在使用Python 2.6.6和scipy版本0.7.2 我不能保证我总是...

python – Scipy odeint给出lsoda警告【代码】

我对编码完全不熟悉,我想用数字方法解决这5个微分方程.我拿了一个python template并将它应用到我的案子中.这是我写的简化版:import numpy as np from math import * from matplotlib import rc, font_manager import matplotlib.pyplot as plt from scipy.integrate import odeint#Constants and parameters alpha=1/137. k=1.e-9 T=40. V= 6.e-6 r = 6.9673e12 u = 1.51856e7#defining dy/dt's def f(y, t):A = y[0]B =...

python – Scipy安装问题,得到ImportError:libopenblas.so.0:无法打开共享对象文件或目录【代码】

我在Ubuntu 14.04上安装Scipy-0.16.1 安装了OpenBLAS_0.2.18和Numpy-1.11.0但没有任何问题. 已下载Scipy-0.16.1.tar.gz site.cfg被复制并取消注释以下行:[openblas]libraries = openblaslibrary_dirs = /opt/OpenBLAS/libinclude_dirs = /opt/OpenBLAS/include在?/ .bashrc中添加了一行export LD_LIBRARY_PATH=/opt/OpenBLAS/lib:$LD_LIBRARY_PATHsource~ / .bashrc LDCONFIG sudo python setup.py配置 错误ImportError: libopenb...

Python / Scipy“标量变量的无效索引”【代码】

我正在使用Scipy优化模块,特别是fmin_tnc和fmin_l_bfgs_b.但是,当使用任何一个时,我收到消息“IndexError:标量变量的无效索引”. 这个错误的原因是什么? 这个错误信息的含义是什么? 我的练习代码:def f01(para):para1, para2 = parareturn 1+ (para1 -1)**2 + (para2 -2)**2para0 = np.array([10, 10]) mybounds = [(-40,30),(-20,15)]opt.fmin_l_bfgs_b(f01, para0, bounds = mybounds )哪个回报:Traceback (most recent c...

python – scipy curve_fit错误:遇到零除零【代码】

我一直试图使用scipy.optimize.curve_fit将函数拟合到某些数据一段时间:from __future__ import (print_function,division,unicode_literals,absolute_import) import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as mpl x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) y = np.array([20.8, 20.9, 22.9, 2...