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">
        <div class="htmledit_views">

1. 函数原型

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


2. 应用

2.1 一维数组

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

[python] view plain copy
print ?
  1. # -*- coding: utf-8 -*-  
  2. import numpy as np  
  3.   
  4. arr = np.random.randint(0,10, (5,))  
  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 二维数组

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

[python] view plain copy
print ?
  1. # -*- coding: utf-8 -*-  
  2. import numpy as np  
  3.   
  4. ”“” 
  5. arr =  
  6.     9 3 7 0  
  7.     3 4 2 4  
  8.     3 6 4 4  
  9.      
  10. index =  
  11.     0   1 
  12.     0   3 
  13.     1   0 
  14.     1   1 
  15.     1   2 
  16.     1   3 
  17.     2   0 
  18.     2   2 
  19.     2   3 
  20. ”“”  
  21.   
  22. arr = np.random.randint(0,10, (3,4))  
  23. 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" target="_blank">Python                     </a><a class="tag-link" href="http://so.csdn.net/so/search/s.do?q=numpy&amp;t=blog" 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" 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" target="_blank">Python</a>

    </div>
        </div>

<!-- !empty($pre_next_article[0]) -->
    </div>
  • 11
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值