打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
numpy.flatnonzero
numpy.flatnonzero(a)[source]

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)>>> xarray([-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])
 
 
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
NumPy使用手记[z]
numpy 中的ndarray类型转为list类型 / list转为ndarray类型
成功解决TypeError: unhashable type: ''numpy.ndarray''
Jupyter Notebook Viewer
数据分析之NumPy(五)数组间运算
Numpy对数组的操作:创建/变形(升降维等)/计算/取值/复制/分割/合并
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服