Below is my code for creating my sparse matrix:
import numpy as np import scipy def sparsemaker(X, Y, Z): 'X, Y, and Z are 2D arrays of the same size' x_, row = np.unique(X, return_inverse=True) y_, col = np.unique(Y, return_inverse=True) return scipy.sparse.csr_matrix( (Z.flat,(row,col)), shape=(x_.size, y_.size) ) >>> print sparsemaker(A, B, C)
Now my input arrays are a little big, so I donโt know how to publish them here (if someone has no ideas); but even looking at the first value, I can already say that something is wrong:
>>> test = sparsemaker(A, B, C) >>> np.max(test.toarray()) 167064.26983076424 >>> np.where(C==np.max(test.toarray())) (array([], dtype=int64), array([], dtype=int64))
Does anyone know why this will happen? Where did this meaning come from?
numpy scipy sparse-matrix
Noob Saibot Jan 22 '13 at 22:20 2013-01-22 22:20
source share