python numpy.nonzero
来源:互联网 发布:淘宝领券的兼职怎么做 编辑:程序博客网 时间:2024/06/03 18:12
- numpy.nonzero(a)
Return the indices of the elements that are non-zero.
Returns a tuple of arrays, one for each dimension of a, containingthe indices of the non-zero elements in that dimension. Thecorresponding 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 foreach non-zero element.
Parameters : a : array_like
Input array.
Returns : tuple_of_arrays : tuple
Indices of elements that are non-zero.
See also
- flatnonzero
- Return indices that are non-zero in the flattened version of the input array.
- ndarray.nonzero
- Equivalent ndarray method.
- count_nonzero
- Counts the number of non-zero elements in the input array.
Examples
>>> x = np.eye(3)>>> xarray([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]])>>> np.nonzero(x)(array([0, 1, 2]), array([0, 1, 2]))
>>> x[np.nonzero(x)]array([ 1., 1., 1.])>>> np.transpose(np.nonzero(x))array([[0, 0], [1, 1], [2, 2]])
A common use for nonzero is to find the indices of an array, wherea condition is True. Given an arraya, the condition a > 3 is aboolean array and since False is interpreted as 0, np.nonzero(a > 3)yields the indices of thea where the condition is true.
>>> a = np.array([[1,2,3],[4,5,6],[7,8,9]])>>> a > 3array([[False, False, False], [ True, True, True], [ True, True, True]], dtype=bool)>>> np.nonzero(a > 3)(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))
The nonzero method of the boolean array can also be called.
>>> (a > 3).nonzero()(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))
- python numpy.nonzero
- python中numpy.nonzero()用法
- numpy.nonzero
- numpy nonzero
- python numpy中nonzero()的用法
- python numpy中nonzero()的用法
- python numpy中nonzero()的用法
- python numpy中nonzero()的用法
- python numpy中nonzero()的用法
- python numpy中nonzero()的用法
- python numpy中nonzero()的用法
- python-numpy中nonzero()的用法
- 【python学习笔记】numpy.nonzero()函数
- numpy nonzero使用方法
- numpy.nonzero函数
- numpy——nonzero
- numpy.nonzero()函数()
- numpy nonzero的用法
- C - sigaction详解
- Android网络存在与否及类型判断
- Trapping Rain Water
- 安装vsftpd
- VC++多线程编程
- python numpy.nonzero
- 利用Java进行MySql数据库的导入和导出
- solr配置自动增量更新索引
- 三大WEB服务器对比分析(apache ,lighttpd,nginx)
- Android json数据解析
- file_get_contents() 函数抓取网页
- First Missing Positive
- Python模块学习 ---- zlib 数据压缩
- 职场分享--职场中如何正确管理好我们的时间?