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を使ったデータ分析、機械学習
52
2
章 
NumPy
の基礎
かに速いオーダーで実行が完了していることがわかります。
In[4]: %timeit (1.0 / big_array)
100 loops, best of 3: 4.6 ms per loop
NumPy
のベクトル化演算は、
ufunc
を使用して実装されます。
ufunc
の主な目的は、
NumPy
配列
の各要素に対して繰り返し演算を素早く実行することです。
ufunc
は非常に柔軟性があります。ス
カラーと配列の間の操作は既に見ましたが、配列同士の操作も可能です。
In[5]: np.arange(5) / np.arange(1, 6)
Out[5]: array([ 0. , 0.5 , 0.66666667, 0.75 , 0.8 ])
また、
ufunc
の演算は
1
次元配列だけに限定されず、多次元配列でも動作します。
In[6]: x = np.arange(9).reshape((3, 3))
2 ** x
Out[6]: array([[ 1, 2, 4],
[ 8, 16, 32],
[ 64, 128, 256]])
ufunc
を使ったベクトル化演算は、特に配列のサイズが大きくなるにつれて
Python
ループを使っ
た実装よりもずっと効率的になります。
Python
スクリプトでこのようなループを見つけたらいつ
でも、ベクトル化された式で置き換えられるかどうかを検討すべきです。
2.3.3
NumPy ufunc
の調査
ufuncs
は、単一入力を操作する単項ufunc
2
つの
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