linalg::nonZeros
-- number of
non-zero elements of a matrixlinalg::nonZeros
(A)
returns the number of
non-zero components of the matrix A.
linalg::nonZeros(A)
A |
- | a matrix of a domain of category Cat::Matrix |
a nonnegative integer
The matrix
>> MZ7 := Dom::Matrix(Dom::IntegerMod(7)): A := MZ7([[18, -1], [4, 81]])
+- -+ | 4 mod 7, 6 mod 7 | | | | 4 mod 7, 4 mod 7 | +- -+
has four non-zero entries:
>> linalg::nonZeros(A)
4
The matrix:
>> B := MZ7([[21, 2], [-1, 14]])
+- -+ | 0 mod 7, 2 mod 7 | | | | 6 mod 7, 0 mod 7 | +- -+
has only two non-zero entries:
>> linalg::nonZeros(B)
2