[Numpy-discussion] Sparse matrices

Victor S. Miller victor at idaccr.org
Tue Jul 30 08:29:06 EDT 2002

Sorry, I had a typo in the program.  It should be:

# M is n by k, and represents a sparse n by n matrix A
# the non-zero entries of row i of A start in column loc[i]
# and are the i-th row of M in locations loc[i]:loc[i]+k
# loc is the location vector
n,k = M.shape
mm = reshape(v,(-1,1))*M
w = zeros((n+m),v.typecode())
# is there a trick to replace the loop below?
for i in range(mm.shape[0]):
    w[loc[i]:loc[i]+k] += mm[i]
w = w[:n]

Victor S. Miller     | " ... Meanwhile, those of us who can compute can hardly
victor at idaccr.org    | be expected to keep writing papers saying 'I can do the
CCR, Princeton, NJ   | following useless calculation in 2 seconds', and indeed
    08540 USA        | what editor would publish them?"  -- Oliver Atkin

More information about the NumPy-Discussion mailing list