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è)人分類:</span>
<a class="tag-link" rel="external nofollow" target="_blank">Python </a>
</div>
<div class="tags-box">
<span class="label">所屬專欄:</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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
PyCharm安裝配置Qt Designer+PyUIC圖文教程
這篇文章主要介紹了PyCharm安裝配置Qt Designer+PyUIC圖文教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-05-05
python中pandas nlargest()的詳細(xì)用法小結(jié)
df.nlargest()是一個(gè)DataFrame的方法,用于返回DataFrame中最大的n個(gè)值所在的行,通過調(diào)用nlargest()方法,我們返回了分?jǐn)?shù)最高的三個(gè)行,并按照降序排列,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2023-10-10
Python實(shí)現(xiàn)的ini文件操作類分享
這篇文章主要介紹了Python實(shí)現(xiàn)的ini文件操作類分享,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-11-11
PyTorch如何搭建一個(gè)簡單的網(wǎng)絡(luò)
這篇文章主要介紹了PyTorch如何搭建一個(gè)簡單的網(wǎng)絡(luò),幫助大家更好的理解和學(xué)習(xí)PyTorch,感興趣的朋友可以了解下2020-08-08
python使用ddddocr庫識(shí)別滑動(dòng)驗(yàn)證碼簡單代碼示例
這篇文章主要介紹了如何使用ddddocr庫來識(shí)別滑塊驗(yàn)證碼,并提供了一個(gè)示例代碼和識(shí)別結(jié)果,同時(shí)提醒注意ddddocr庫的大小限制,可能會(huì)影響某些無服務(wù)器函數(shù)的部署,需要的朋友可以參考下2024-11-11
Python內(nèi)置函數(shù)——__import__ 的使用方法
本篇文章主要介紹了Python內(nèi)置函數(shù)——__import__ 的使用方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11
python抓取某汽車網(wǎng)數(shù)據(jù)解析html存入excel示例
python抓取某汽車網(wǎng)經(jīng)銷商信息網(wǎng)頁數(shù)據(jù)解析html,這里提供一個(gè)示例演示,大家可以根據(jù)需要分析自己網(wǎng)站的數(shù)據(jù)2013-12-12

