numpy如何获取array中数组元素的索引位置
目录
- numpy - 获取array中数组元素的索引
- 1. 函数原型
- 2. 应用
- 2.1 一维数组
- 2. 2 二维数组
numpy - 获取array中数组元素的索引
<div class="article-info-box"> <div class="article-bar-top d-Flex"> <span class="SMaJtfVNwtime">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/htmledi开发者_JS学习t_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&t=blog" rel="external nofollow" target="_blanphpk">Python </a><a class="tag-link"android href="http://so.csdn.net/so/search/s.do?q=numpy&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数组索引内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!
精彩评论