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を使ったデータ分析、機械学習
2.6
 比較、マスク、ブール論理
75
2.6.4
 マスクとしてのブール値配列
前の節では、ブール値配列を直接計算して集約値を求めました。より強力なパターンは、ブール
値配列をマスクとして使用して、データ自体の特定のサブセットを選択することです。先に作成し
x
配列の中で、例えば
5
より小さい値だけを含む配列が必要であるとします。
In[26]: x
Out[26]: array([[5, 0, 3, 3],
[7, 9, 3, 5],
[2, 4, 7, 6]])
既に見たように、この条件のブール値配列を得るのは簡単です。
In[27]: x < 5
Out[27]: array([[False, True, True, True],
[False, False, True, False],
[ True, True
, False, False]], dtype=bool)
ここで配列からこれらの値を選択するには、このブール値配列をインデクスとして指定するだけ
です。これはマスキング操作として知られています。
In[28]: x[x < 5]
Out[28]: array([0, 3, 3, 3, 2, 4])
この条件を満たす値を埋めた
1
次元配列が返されます。つまり、マスク配列が
True
の位置にある
すべての値が得られます。この後、これらの値を自由に操作できます。例えば、シアトル市の降水
量に関する統計量を計算します。
In[29]:
# construct a mask of all rainy days
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