[SciPy-User] Thresholding in sparse matrices

Jaidev Deshpande deshpande.jaidev@gmail....
Thu Oct 11 13:57:46 CDT 2012


Hi,

When constructing a sparse matrix, (for instance, using
scipy.sparse.coo_matrix) does the function take into account any
tolerance? In other words, does an element have to be exactly zero to
be casted as a zero in the sparse matrix? Can a tolerance value be
specified below which every element would be casted as zero?

Suppose I have a matrix x:

>>> x = np.array([1e-3, 1e-5, 1e-10])
>>> coo_matrix(x)
<1x3 sparse matrix of type '<type 'numpy.float64'>'
	with 3 stored elements in COOrdinate format>

Now, I want x[1] and x[2] to be zeros, because they are less than
0.001 (say). This thresholding can be done on the array x itself, but
I wonder if there is a way to do this through the sparse constructors.

Thanks


More information about the SciPy-User mailing list