Registered Member
|
The documentation for the nonZeros() method on a dense matrix states:
The following code outputs 10, however:
I take it for a dense matrix nonZeros() always gives the size of the matrix, despite the documentation stating that it is the "the number of nonzero coefficients"? Not a big deal, I can do something like this instead, but it seems like it could be inefficient:
Thanks for the clarification! |
Moderator
|
Right, the documentation is not very clear as this method is useful for sparse matrices only, and available on dense matrices for API compatibility. Here "non-zeros" really means explicitly stored coefficients. You can use the count() method to simplify the expression:
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]