numpy如何获取array中数组元素的索引位置

 更新时间:2023年01月18日 10:31:42   作者:yuan0061  
这篇文章主要介绍了numpy获取array中数组元素的索引位置,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

numpy - 获取array中数组元素的索引

<div class="article-info-box">
    <div class="article-bar-top d-flex">
                                            <span class="time">2017年08月05日 10:36:59</span>
        <div class="float-right">
            <span class="read-count">阅读数:1797</span>
                                        </div>
    </div>
</div>
<article>
    <div id="article_content" class="article_content clearfix csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post">
                <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/htmledit_views-0a60691e80.css" rel="external nofollow" >
        <div class="htmledit_views">

1. 函数原型

argwhere(array):找到非空数组array在满足某些条件下的索引,返回索引数组。

2. 应用

2.1 一维数组

返回一个一维数组,代表当前满足条件的元素出现的位置。

# -*- coding: utf-8 -*-  
import numpy as np  
  
arr = np.random.randint(0,10, (5,))  
index = np.argwhere(arr < 5)
# -*- coding: utf-8 -*-
import numpy as np

arr = np.random.randint(0,10, (5,))
index = np.argwhere(arr < 5)

2. 2 二维数组

返回二维数组,代表当前满足条件的元素出现的位置。

# -*- coding: utf-8 -*-  
import numpy as np  
  
”“” 
arr =  
    9 3 7 0  
    3 4 2 4  
    3 6 4 4  
     
index =  
    0   1 
    0   3 
    1   0 
    1   1 
    1   2 
    1   3 
    2   0 
    2   2 
    2   3 
”“”  
arr = np.random.randint(0,10, (3,4))  
index = np.argwhere(arr < 5)  
# -*- coding: utf-8 -*-
import numpy as np

"""
arr = 
    9 3 7 0 
    3 4 2 4 
    3 6 4 4 

index = 
    0   1
    0   3
    1   0
    1   1
    1   2
    1   3
    2   0
    2   2
    2   3
"""

arr = np.random.randint(0,10, (3,4))
index = np.argwhere(arr < 5)

参考文献

http://blog.csdn.net/vernice/article/details/50990919

            </div>
        </article>

    <div class="article-bar-bottom">
            <div class="article-copyright">
        版权声明:本文为博主原创文章,未经博主允许不得转载。          https://blog.csdn.net/ZK_J1994/article/details/76707734     </div>
                    <div class="tags-box artic-tag-box">
        <span class="label">文章标签:</span>
                    <a class="tag-link" href="http://so.csdn.net/so/search/s.do?q=Python&amp;t=blog" rel="external nofollow"  target="_blank">Python                     </a><a class="tag-link" href="http://so.csdn.net/so/search/s.do?q=numpy&amp;t=blog" rel="external nofollow"  target="_blank">numpy                       </a>
    </div>
                    <div class="tags-box">
        <span class="label">个人分类:</span>
                    <a class="tag-link" href="https://blog.csdn.net/zk_j1994/article/category/6550054" rel="external nofollow"  target="_blank">Python                       </a>
    </div>
                    <div class="tags-box">
        <span class="label">所属专栏:</span>
                    <a class="tag-link" href="https://blog.csdn.net/column/details/16129.html" rel="external nofollow"  target="_blank">Python</a>

    </div>
        </div>

<!-- !empty($pre_next_article[0]) -->
    </div>

到此这篇关于numpy获取array中数组元素的索引位置的文章就介绍到这了,更多相关numpy array数组索引内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Python基于回溯法子集树模板实现图的遍历功能示例

    Python基于回溯法子集树模板实现图的遍历功能示例

    这篇文章主要介绍了Python基于回溯法子集树模板实现图的遍历功能,结合实例形式分析了Python使用回溯法子集树模板针对图形遍历问题的相关操作技巧与注意事项,需要的朋友可以参考下
    2017-09-09
  • 跟老齐学Python之有容乃大的list(1)

    跟老齐学Python之有容乃大的list(1)

    这一讲中的list类型,也是python的一种数据类型。翻译为:列表。LIST在python中具有非常强大的功能。
    2014-09-09
  • 在python3.5中使用OpenCV的实例讲解

    在python3.5中使用OpenCV的实例讲解

    下面小编就为大家分享一篇在python3.5中使用OpenCV的实例讲解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-04-04
  • python自动下载图片的方法示例

    python自动下载图片的方法示例

    这篇文章主要介绍了python自动下载图片的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-03-03
  • python使用Tesseract库识别验证

    python使用Tesseract库识别验证

    这篇文章主要为大家详细介绍了python使用Tesseract库识别验证,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-03-03
  • Django 对IP访问频率进行限制的例子

    Django 对IP访问频率进行限制的例子

    今天小编就为大家分享一篇Django 对IP访问频率进行限制的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-08-08
  • Python使用signal定时结束AsyncIOScheduler任务的问题

    Python使用signal定时结束AsyncIOScheduler任务的问题

    这篇文章主要介绍了Python使用signal定时结束AsyncIOScheduler任务,在使用aiohttp结合apscheduler的AsyncIOScheduler模拟定点并发的时候遇到两个问题,针对每个问题给大家详细介绍,需要的朋友可以参考下
    2021-07-07
  • 详解selenium + chromedriver 被反爬的解决方法

    详解selenium + chromedriver 被反爬的解决方法

    这篇文章主要介绍了详解selenium + chromedriver 被反爬的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-10-10
  • Python学习开发之图形用户界面详解

    Python学习开发之图形用户界面详解

    当前流行的计算机桌面应用程序大多数为图形化用户界面(Graphic User Interface,GUI),python也提供了多个图形开发界面的库,这篇文章主要给大家介绍了关于Python学习开发之图形用户界面的相关资料,需要的朋友可以参考下
    2021-08-08
  • python计算一个序列的平均值的方法

    python计算一个序列的平均值的方法

    这篇文章主要介绍了python计算一个序列的平均值的方法,涉及Python递归遍历与数学计算的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-07-07

最新评论