mars.tensor.count_nonzero¶

mars.tensor.
count_nonzero
(a, axis=None, combine_size=None)[source]¶ Counts the number of nonzero values in the tensor
a
.The word “nonzero” is in reference to the Python 2.x builtin method
__nonzero__()
(renamed__bool__()
in Python 3.x) of Python objects that tests an object’s “truthfulness”. For example, any number is considered truthful if it is nonzero, whereas any string is considered truthful if it is not the empty string. Thus, this function (recursively) counts how many elements ina
(and in subtensors thereof) have their__nonzero__()
or__bool__()
method evaluated toTrue
. Parameters
 Returns
count – Number of nonzero values in the array along a given axis. Otherwise, the total number of nonzero values in the tensor is returned.
 Return type
int or tensor of int
See also
nonzero
Return the coordinates of all the nonzero values.
Examples
>>> import mars.tensor as mt
>>> mt.count_nonzero(mt.eye(4)).execute() 4 >>> mt.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]]).execute() 5 >>> mt.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]], axis=0).execute() array([1, 1, 1, 1, 1]) >>> mt.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]], axis=1).execute() array([2, 3])