### Navigation

- index
- modules |
- next |
- previous |
- NumPy v1.3 Manual (DRAFT) »
- NumPy Reference »
- Routines »
- Sorting and searching »

# numpy.nonzero

`numpy.``nonzero`(a)

  Return the indices of the elements that are non-zero.

  Returns a tuple of arrays, one for each dimension of a, containing the indices of the non-zero elements in that dimension. The corresponding non-zero values can be obtained with:

      a[nonzero(a)]

  To group the indices by element, rather than dimension, use:

      transpose(nonzero(a))

  The result of this is always a 2-D array, with a row for each non-zero element.

  Parameters: | a : array_like Input array.
  Returns: | tuple_of_arrays : tuple Indices of elements that are non-zero.

  See also

  `flatnonzero`
    Return indices that are non-zero in the flattened version of the input array.
  `ndarray.nonzero`
    Equivalent ndarray method.

  Examples

      >>> x = np.eye(3)
      >>> x
      array([[ 1.,  0.,  0.],
             [ 0.,  1.,  0.],
             [ 0.,  0.,  1.]])
      >>> np.nonzero(x)
      (array([0, 1, 2]), array([0, 1, 2]))

      >>> x[np.nonzero(x)]
      array([ 1.,  1.,  1.])
      >>> np.transpose(np.nonzero(x))
      array([[0, 0],
             [1, 1],
             [2, 2]])

### Navigation

- index
- modules |
- next |
- previous |
- NumPy v1.3 Manual (DRAFT) »
- NumPy Reference »
- Routines »
- Sorting and searching »