numpy如何獲取array中數(shù)組元素的索引位置
numpy - 獲取array中數(shù)組元素的索引
<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">閱讀數(shù):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" rel="external nofollow" >
<div class="htmledit_views">1. 函數(shù)原型
argwhere(array):找到非空數(shù)組array在滿足某些條件下的索引,返回索引數(shù)組。
2. 應(yīng)用
2.1 一維數(shù)組
返回一個(gè)一維數(shù)組,代表當(dāng)前滿足條件的元素出現(xiàn)的位置。
# -*- 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 二維數(shù)組
返回二維數(shù)組,代表當(dāng)前滿足條件的元素出現(xiàn)的位置。
# -*- 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)參考文獻(xiàn)
http://blog.csdn.net/vernice/article/details/50990919
</div>
</article>
<div class="article-bar-bottom">
<div class="article-copyright">
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。 https://blog.csdn.net/ZK_J1994/article/details/76707734 </div>
<div class="tags-box artic-tag-box">
<span class="label">文章標(biāo)簽:</span>
<a class="tag-link" rel="external nofollow" target="_blank">Python </a><a class="tag-link" rel="external nofollow" target="_blank">numpy </a>
</div>
<div class="tags-box">
<span class="label">個(gè)人分類(lèi):</span>
<a class="tag-link" rel="external nofollow" target="_blank">Python </a>
</div>
<div class="tags-box">
<span class="label">所屬專(zhuān)欄:</span>
<a class="tag-link" rel="external nofollow" target="_blank">Python</a>
</div>
</div>
<!-- !empty($pre_next_article[0]) -->
</div>到此這篇關(guān)于numpy獲取array中數(shù)組元素的索引位置的文章就介紹到這了,更多相關(guān)numpy array數(shù)組索引內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
簡(jiǎn)單學(xué)習(xí)Python time模塊
這篇文章主要和大家一起簡(jiǎn)單學(xué)習(xí)一下Python time模塊,Python time模塊提供了一些用于管理時(shí)間和日期的C庫(kù)函數(shù),對(duì)time模塊感興趣的小伙伴們可以參考一下2016-04-04
python中plot實(shí)現(xiàn)即時(shí)數(shù)據(jù)動(dòng)態(tài)顯示方法
這篇文章主要為大家詳細(xì)介紹了python中plot實(shí)現(xiàn)即時(shí)數(shù)據(jù)動(dòng)態(tài)顯示方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06
python使用Pyinstaller如何打包整個(gè)項(xiàng)目
這篇文章主要介紹了python使用Pyinstaller如何打包整個(gè)項(xiàng)目,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
python heic后綴圖片文件轉(zhuǎn)換成jpg格式的操作
這篇文章主要介紹了python heic后綴圖片文件轉(zhuǎn)換成jpg格式的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-03-03

