Open In App

numpy.ma.MaskedArray.nonzero() function - Python

Last Updated : 05 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
numpy.ma.MaskedArray.nonzero() function return the indices of unmasked elements that are not zero. This function returns a tuple of arrays, one for each dimension, containing the indices of the non-zero elements in that dimension.
Syntax : numpy.ma.MaskedArray.nonzero(self) Return : [tuple] Indices of elements that are non-zero.
Code #1 :
Output :
(array([0, 1, 2, 3, 4]), array([0, 1, 2, 3, 4]))
  Code #2 :
Output :
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))

Next Article

Similar Reads