Hi everyone,
I want to count the number of non-zero entries in a matrix but I can't find a Sage command to do this. Instead, I found a NumPy command numpy.count_nonzero to do it.
The code goes like this: import numpy as np
mm = matrix(ZZ, 2, 3, [1,0,2,0,0,0])
print mm
print np.count_nonzero(mm)
It worked in the Sage Cell Server. However, when I tried it out in Sage v5.12 in Linux. There is an error message: " 'module' object has no attribute 'count_nonzero' ". Also, when I typed numpy.<tab> to see all possible commands, numpy.count_nonzero does not appear. It seems as though there is no such command.
I am willing to use other simple commands as long as I get to count the nonzero entries of a matrix. Perhaps someone can help me with this...
Thanks!
Cheers,
Eileen.