日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

numpy如何獲取array中數組元素的索引位置_python

作者:yuan0061 ? 更新時間: 2023-03-16 編程語言

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    >
        <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"    target="_blank">Python                     </a><a class="tag-link"    target="_blank">numpy                       </a>
    </div>
                    <div class="tags-box">
        <span class="label">個人分類:</span>
                    <a class="tag-link"    target="_blank">Python                       </a>
    </div>
                    <div class="tags-box">
        <span class="label">所屬專欄:</span>
                    <a class="tag-link"    target="_blank">Python</a>

    </div>
        </div>

<!-- !empty($pre_next_article[0]) -->
    </div>

原文鏈接:https://blog.csdn.net/yuan0061/article/details/80378575

欄目分類
最近更新