Sparse Matrix Multiplications

Peter Otten __peter__ at web.de
Tue May 13 05:10:38 EDT 2008


Peter Otten wrote:

> Peter Otten wrote:
> 
>> # use at your own risk
>> import numpy
>> 
>> N = 10**4 # I get a MemoryError for a bigger exponent
>> b = numpy.array(range(N))
>> a = numpy.zeros((N, N)) + b
>> a *= a.transpose()
>> a[0,0] = (b*b).sum()
>> print a
> 
> Sorry, this is nonsense.

Maybe not as bad as I feared. I seems you can't transpose and
inplace-multiply, so

# use at your own risk
import numpy

N = 5
b = numpy.array(range(N))
a = numpy.zeros((N, N)) + b
a = a * a.transpose()
a[0,0] = (b*b).sum()
print a

might work if there is sufficient memory available...

Peter



More information about the Python-list mailing list