码迷,mamicode.com
首页 > 编程语言 > 详细

[Python] numpy.nonzero

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

标签:dimen   imp   res   pos   turned   val   name   tran   pre   

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

标签:dimen   imp   res   pos   turned   val   name   tran   pre   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!