Numexpr不识别浮点类型(稀疏矩阵)

时间:2015-11-20 10:41:19

标签: python python-2.7 numpy timeit numexpr

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

我做错了什么?

代码:

document.addEventListener("DOMContentLoaded", function (e) {
    var delayedImages = document.querySelectorAll("img[data-src]");
    for (var i = 0; i < delayedImages.length; i++) {
        delayedImages[i].src = delayedImages[i].getAttribute("data-src");
    }
});

错误:

追踪(最近一次呼叫最后一次):

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

1 个答案:

答案 0 :(得分:3)

body > div.content > div { position: relative; display: inline-table; border: 1px solid #E9EAED; box-shadow: 0px 0px 1px #E9EAED; background: #ffffff; border-radius: 2px; padding: 10px; } 期望变量是numpy数组。它没有处理scipy的稀疏矩阵。 (例如,请参阅此电子邮件主题:http://numpy-discussion.10968.n7.nabble.com/ANN-numexpr-2-3-final-released-td36154.html