我想在python (2.7)中评估numexpr模块的性能。为此,我创建了一个随机稀疏矩阵的大小(10^5,10^5)。但是,下面的脚本已经在表达式计算步骤中抛出一个错误,表示它不识别对象类型。
我做错了什么?
代码:
import timeit
import scipy.sparse as sps
import numpy as np
import numexpr as ne
test_matrix = sps.rand(1e4, 1e4, density=0.01, format='coo', dtype = np.float32)
ne.evaluate('sum(test_matrix, axis = 1)')
setup = 'import numexpr as ne; import numpy as np'
print min(timeit.Timer('ne.evaluate(sum(test_matrix, axis = 1))', setup=setup).repeat(7, 1000))错误:
回溯(最近一次调用):
File "benchmark_expressmath.py", line 19, in <module>
ne.evaluate('sum(test_matrix, axis = 1)')
File "C:\Users\blahblah\AppData\Local\Continuum\Anaconda\lib\site-packages\numexpr\necompiler.py", line 756, in evaluate
signature = [(name, getType(arg)) for (name, arg) in zip(names, arguments)]
File "C:\Users\blahblah\AppData\Local\Continuum\Anaconda\lib\site-packages\numexpr\necompiler.py", line 654, in getType
raise ValueError("unknown type %s" % a.dtype.name)
ValueError: unknown type object发布于 2015-11-20 11:31:18
numexpr期望变量是numpy数组。它不处理席比的稀疏矩阵。(参见,例如,这个电子邮件线程:http://numpy-discussion.10968.n7.nabble.com/ANN-numexpr-2-3-final-released-td36154.html)
https://stackoverflow.com/questions/33824617
复制相似问题