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を使ったデータ分析、機械学習
96
2
章 
NumPy
の基礎
2.9.3
RecordArrays
:構造化配列の変形版
NumPy
はレコード配列
np.recarray
クラスも提供しています。これは、前述の構造化配列とほ
とんど同じですが、フィールドには辞書キーではなく属性としてアクセスできる点が異なります。
私たちはこれまで、次のようにして
age
配列にアクセスしたことを思い出してください。
In[15]: data['age']
Out[15]: array([25, 45, 37, 19], dtype=int32)
代わりにデータをレコード配列にすると、少ないキーストロークでデータにアクセスできます。
In[16]: data_rec = data.view(np.recarray)
data_rec.age
Out[16]: array([25, 45, 37, 19], dtype=int32)
レコード配列の欠点は、同じ構文を使用している場合でも、フィールドへのアクセスに伴う余分
なオーバーヘッドがあることです。次のようにして確認できます。
In[17]: %timeit data['age']
%timeit data_rec['age']
%timeit data_rec.age
1000000 loops, best of 3: 241 ns per loop
100000 loops, best of 3: 4.61
μ
s per loop
100000 loops, best of 3: 7.27
μ
s per loop ...
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