前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >numpy.nonzero()函数

numpy.nonzero()函数

作者头像
听城
发布2018-04-27 15:52:03
5190
发布2018-04-27 15:52:03
举报
文章被收录于专栏:杂七杂八杂七杂八

官方文档如下: 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 a are always tested and returned in row-major, C-style order. 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. 简单来说就是参数是数组或者矩阵,返回值为该数组或者矩阵中非零元素的下标值构成的元组。该元组有两维,第一维是非零元素所在的行,第二维是非零元素所在的列。 如果

代码语言:javascript
复制
a=mat([ [1,0,0],         
       [1,0,0],
        [0,0,0]])                      

则 nonzero(a) 返回值为 (array([0, 1]), array([0, 0])) , 因为矩阵a只有两个非零值, 在第0行、第0列,和第1行、第0列。所以结果元组中,第一个行维度数据为(0,1) 元组第二个列维度都为(0,0)。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.09.13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档