首页 > 编程语言 > 详细

[Python] numpy.nonzero

时间:2017-03-26 11:49:44      阅读:218      评论:0      收藏:0      [点我收藏+]

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]]

  

[Python] numpy.nonzero

原文:http://www.cnblogs.com/KennyRom/p/6621770.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!