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. 應用
2.1 一維數(shù)組
返回一個一維數(shù)組,代表當前滿足條件的元素出現(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ù)組,代表當前滿足條件的元素出現(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)參考文獻
http://blog.csdn.net/vernice/article/details/50990919
</div>
</article>
<div class="article-bar-bottom">
<div class="article-copyright">
版權聲明:本文為博主原創(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">文章標簽:</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">個人分類:</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>到此這篇關于numpy獲取array中數(shù)組元素的索引位置的文章就介紹到這了,更多相關numpy array數(shù)組索引內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
PyCharm安裝配置Qt Designer+PyUIC圖文教程
這篇文章主要介紹了PyCharm安裝配置Qt Designer+PyUIC圖文教程,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-05-05
python中pandas nlargest()的詳細用法小結
df.nlargest()是一個DataFrame的方法,用于返回DataFrame中最大的n個值所在的行,通過調(diào)用nlargest()方法,我們返回了分數(shù)最高的三個行,并按照降序排列,本文結合實例代碼給大家介紹的非常詳細,需要的朋友參考下吧2023-10-10
Python內(nèi)置函數(shù)——__import__ 的使用方法
本篇文章主要介紹了Python內(nèi)置函數(shù)——__import__ 的使用方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11
python抓取某汽車網(wǎng)數(shù)據(jù)解析html存入excel示例
python抓取某汽車網(wǎng)經(jīng)銷商信息網(wǎng)頁數(shù)據(jù)解析html,這里提供一個示例演示,大家可以根據(jù)需要分析自己網(wǎng)站的數(shù)據(jù)2013-12-12

