这可能不是你正在寻找的答案,但加速它的一种方法是使用gpu而不是你的cpu.如果你有一个相当强大的显卡,它会在任何一天都超过你的CPU,即使你的系统调整得很好.
为了与numpy很好地集成,你可以使用theano(如果你的显卡是由nvidia制作的).以下代码中的计算在几秒钟内为我运行(尽管我有一个非常强大的图形卡):
$THEANO_FLAGS=device=gpu0 python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
Using gpu device 0: GeForce GTX 480
>>> from theano import tensor as T
>>> import numpy
>>> x = numpy.ones((200000, 1000), dtype=numpy.float32)
>>> m = T.matrix()
>>> mTm = T.dot(m.T, m)
>>> f = theano.function([m], mTm)
>>> f(x)
array([[ 200000., 200000., 200000., ..., 200000., 200000., 200000.],
[ 200000., 200000., 200000., ..., 200000., 200000., 200000.],
[ 200000., 200000., 200000., ..., 200000., 200000., 200000.],
...,
[ 200000., 200000., 200000., ..., 200000., 200000., 200000.],
[ 200000., 200000., 200000., ..., 200000., 200000., 200000.],
[ 200000., 200000., 200000., ..., 200000., 200000., 200000.]], dtype=float32)
>>> r = f(x)
>>> r.shape
(1000, 1000)
我打算等待多长时间>>> numpy.dot(x.T,x)采取比较的方式,但我感到无聊……
你也可以尝试PyCuda或PyOpenCL(如果你没有nvidia显卡),虽然我不知道他们的numpy支持是否如此简单.