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 values in aare always tested and returned in row-major, C-style order. The corresponding non-zero  values can be obtained with:

 

 
import numpy as np

a = np.eye(3);

print np.nonzero(a)
#(array([0, 1, 2]), array([0, 1, 2]))

  

print np.transpose(np.nonzero(a))
#[[0 0]
# [1 1]
# [2 2]]

  

相关文章:

  • 2021-12-15
  • 2021-06-12
  • 2021-09-19
  • 2021-07-04
  • 2022-01-22
  • 2021-10-10
  • 2021-06-16
  • 2021-06-20
猜你喜欢
  • 2021-11-04
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-01-07
相关资源
相似解决方案