The functions described in the table of section 2.5 also work with sparse matrix arguments. The difference is that for a sparse matrix only the nonzero entries are considered.
x) |
[x]) |
False
if x has at least one
nonzero entry; False
otherwise.
x) |
x) |
x) |
x[, start=0.0]) |
The functions list(), tuple(), zip(), map(), filter() also take sparse matrix arguments. They work as for dense matrices, again with the difference that only the nonzero entries are considered.
In the following example we square the entries of the matrix (6.2).
>>> A = spmatrix([2,1,2,2,1,3,4], [1,2,0,2,3,0,2], [0,0,1,1,2,3,3]) >>> B = spmatrix(map(lambda x: x**2, A), A.I, A.J) >>> print B SIZE: (4,4) (1, 0) 4.0000e+00 (2, 0) 1.0000e+00 (0, 1) 4.0000e+00 (2, 1) 4.0000e+00 (3, 2) 1.0000e+00 (0, 3) 9.0000e+00 (2, 3) 1.6000e+01
The expression "x in A" returns True
if a nonzero
entry of A is equal to x and False
otherwise.