Numexpr无法识别浮点类型(稀疏矩阵) [英] Numexpr doesn't recognize float type (sparse matrix)

查看:268
本文介绍了Numexpr无法识别浮点类型(稀疏矩阵)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想评估python(2.7)中numexpr模块的性能.为此,我创建了一个大小为(10 ^ 5,10 ^ 5)的随机稀疏矩阵.但是,下面的脚本已经在表达式求值步骤中引发了错误,说它无法识别对象类型.

I would like to evaluate the performance of numexpr module in python (2.7). For that purpose, I created a random sparse matrix of size (10^5, 10^5). However, the script below throws an error at the expression evaluation step already, saying that it doesn't recognize the object type.

我在做什么错了?

代码:

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))

错误:

回溯(最近通话最近一次):

Traceback (most recent call last):

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

推荐答案

numexpr期望变量为numpy数组.它不处理scipy的稀疏矩阵. (例如,请参阅此电子邮件线程:

numexpr expects the variables to be numpy arrays. It doesn't handle scipy's sparse matrices. (See, for example, this email thread: http://numpy-discussion.10968.n7.nabble.com/ANN-numexpr-2-3-final-released-td36154.html)

这篇关于Numexpr无法识别浮点类型(稀疏矩阵)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆