码迷,mamicode.com
首页 > 其他好文 > 详细

numpy之flatnonzero函数

时间:2018-03-29 00:03:56      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:font   col   tput   span   frame   amp   generate   nts   AC   

Return indices that are non-zero in the flattened version of a.

This is equivalent to a.ravel().nonzero()[0].

Parameters:

a : ndarray

Input array.

Returns:

res : ndarray

Output array, containing the indices of the elements of a.ravel() that are non-zero.

See also

nonzero
Return the indices of the non-zero elements of the input array.
ravel
Return a 1-D array containing the elements of the input array.

Examples

>>> x = np.arange(-2, 3)
>>> x
array([-2, -1,  0,  1,  2])
>>> np.flatnonzero(x)
array([0, 1, 3, 4])

Use the indices of the non-zero elements as an index array to extract these elements:

>>> x.ravel()[np.flatnonzero(x)]
array([-2, -1,  1,  2])

numpy之flatnonzero函数

标签:font   col   tput   span   frame   amp   generate   nts   AC   

原文地址:https://www.cnblogs.com/qinduanyinghua/p/8666592.html

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