Skip to Content
Pythonデータサイエンスハンドブック ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習
book

Pythonデータサイエンスハンドブック ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

by Jake VanderPlas, 菊池 彰
May 2018
Intermediate to advanced
556 pages
13h 21m
Japanese
O'Reilly Japan, Inc.
Content preview from Pythonデータサイエンスハンドブック ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習
78
2
章 
NumPy
の基礎
2.7
 ファンシーインデクス
前の節では、単純なインデクス(例えば
arr[0]
)、スライス(例えば
arr[
5]
)、ブール値マスク
(例えば
arr[arr > 0]
)を使用して配列の一部にアクセスし、その内容を変更する方法を見てきま
した。この節では、ファンシーインデクスと呼ばれる別のスタイルの配列インデクスを見ていきま
す。ファンシーインデクスは既に見てきた単純なインデクスのようですが、単一のスカラー値の代
わりにインデクスの配列を渡します。こうすることで、配列の複雑なサブセットに迅速にアクセス
し、内容を変更することができます。
2.7.1
 ファンシーインデクスの調査
ファンシーインデクスの概念は単純です。インデクスの配列を渡して、複数の配列要素に同時に
アクセスします。例えば、次の配列で考えてみましょう
1
In[1]: import numpy as np
rand = np.rando
m.RandomState(42)
x = rand.randint(100, size=10)
print(x)
[51 92 14 71 60 20 82 86 74 74]
この中の
3
つの要素にアクセスしたい場合、おそらく次の方法を使います。
In[2]: [x[3], x[7], x[2]]
Out[2]: [71, 86, 14]
インデクスのリストまたは配列を渡して、同じ結果が得られます。
In[3]: ind = [3, 7, 4]
x[ind]
Out[3]: array([71, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pythonデータサイエンスハンドブック 第2版 ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

Pythonデータサイエンスハンドブック 第2版 ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

Jake VanderPlas, 菊池 彰
初めてのGraphQL ―Webサービスを作って学ぶ新世代API

初めてのGraphQL ―Webサービスを作って学ぶ新世代API

Eve Porcello, Alex Banks, 尾崎 沙耶, あんどうやすし

Publisher Resources

ISBN: 9784873118413Other