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函数的更多相关文章

  1. 为什么你用不好Numpy的random函数?

    为什么你用不好Numpy的random函数? 在python数据分析的学习和应用过程中,经常需要用到numpy的随机函数,由于随机函数random的功能比较多,经常会混淆或记不住,下面我们一起来汇总学 ...

  2. np.random.random()函数 参数用法以及numpy.random系列函数大全

    原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/9751471.html 1.np.random.random()函数参数 np.random.r ...

  3. NumPy数学算数函数

    NumPy - 算数函数 很容易理解的是,NumPy 包含大量的各种数学运算功能. NumPy 提供标准的三角函数,算术运算的函数,复数处理函数等. 三角函数 NumPy 拥有标准的三角函数,它为弧度 ...

  4. Python之Numpy库常用函数大全(含注释)

    前言:最近学习Python,才发现原来python里的各种库才是大头! 于是乎找了学习资料对Numpy库常用的函数进行总结,并带了注释.在这里分享给大家,对于库的学习,还是用到时候再查,没必要死记硬背 ...

  5. 【转】np.random.random()函数 参数用法以及numpy.random系列函数大全

    转自:https://www.cnblogs.com/DOMLX/p/9751471.html 1.np.random.random()函数参数 np.random.random((1000, 20) ...

  6. Numpy | 14 字符串函数

    本章函数用于对 dtype 为 numpy.string_ 或 numpy.unicode_ 的数组执行向量化字符串操作. 它们基于 Python 内置库中的标准字符串函数. 这些函数在字符数组类(n ...

  7. Python之Numpy库常用函数大全(含注释)(转)

    为收藏学习,特转载:https://blog.csdn.net/u011995719/article/details/71080987 前言:最近学习Python,才发现原来python里的各种库才是 ...

  8. numpy的divide函数

    和直接用/一样,都是矩阵的对应元素相除. 如果用*,那么是矩阵的对应元素相乘. 如果要实现矩阵乘法,用numpy的dot函数.

  9. scipy几乎实现numpy的所有函数

    NumPy和SciPy的关系?   numpy提供了数组对象,面向的任何使用者.scipy在numpy的基础上,面向科学家和工程师,提供了更为精准和广泛的函数.scipy几乎实现numpy的所有函数, ...

随机推荐

  1. android开发学习 ------- 【转】 android中的线程池

    线程很常见 , https://blog.csdn.net/seu_calvin/article/details/52415337    参考,保证能看懂.

  2. 死磕 java并发包之AtomicStampedReference源码分析(ABA问题详解)

    问题 (1)什么是ABA? (2)ABA的危害? (3)ABA的解决方法? (4)AtomicStampedReference是什么? (5)AtomicStampedReference是怎么解决AB ...

  3. decompressedResponseImageOfSize:completionHandler:]_block_invoke

    原因:   It turns out the linker error was caused by the CGImageSourceCreateWithData call. And the root ...

  4. Entity Framework插入数据报错:Validation failed for one or more entities

    www.111cn.net 编辑:lanve 来源:转载 今天在处理Entity Framework插入数据库时,报错: Validation failed for one or more entit ...

  5. DaemonSet 案例分析

    本节详细分析两个 k8s 自己的 DaemonSet:kube-flannel-ds 和 kube-proxy . kube-flannel-ds 下面我们通过分析 kube-flannel-ds 来 ...

  6. github+hexo+themes搭建简易个性主题博客

    0x00  install Node.js and git 安装Node.js:http://www.runoob.com/nodejs/nodejs-install-setup.html 安装git ...

  7. Luogu P3938 斐波那契

    Luogu P3938 斐波那契 第一眼看到这题,想到的是LCA,于是开始想怎么建树,倒是想出了\(n^{2}\)算法,看了下数据范围,果断放弃 想了想这数据范围,大的有点不正常,这让我想起了当年被小 ...

  8. hihoCoder-1093-SPFA

    SPFA的卓越之处就在于处理多点稀疏图,因为点太多的话,我们直接用矩阵来存图的话是存不下的. 所以当我们用邻接矩阵来存图的话,我们就可以用SPFA来解决这类问题,spfa就是优化版的bellman-f ...

  9. HDU-1009-肥鼠交易

    这题是一道简单的可拆分的贪心题目,需要注意的是,我们定义的结构体里面都应该用double类型, 或者float类型,不然两个int相除,就失去了精度(强转也可以). #include <cstd ...

  10. (21)zabbix创建触发器trigger

    1. 创建触发器 了解了什么触发器,接下来看下zabbix触发器怎么创建和配置,方法很简单,请大家往下读,有什么问题请留言. 创建触发器步骤: 点击Configuration(配置) → Hosts( ...