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数组索引内容请搜索编程宝库以前的文章,希望以后支持编程宝库

 一、什么是yield如果还没有怎么用过的话,直接把yield看做成一种特殊的return(PS:本质 generator(生成器))return是返回一个值然后就终断函数了 ...