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.1
Python
のデータ型について
39
2.1.4
Python
のリストから作る配列
最初は
np.array
を使った
Python
リストからの配列作成です。
In[8]: # integer array:
整数配列
np.array([1, 4, 2, 5, 3])
Out[8]: array([1, 4, 2, 5, 3])
Python
リストとは異なり、
NumPy
配列の要素はすべて同じ型という制約があります。型が一致
しない場合、可能であれば
NumPy
はアップキャストします(ここでは、整数は浮動小数点にアッ
プキャストされます)。
In[9]: np.array([3.14, 4, 2, 3])
Out[9]: array([ 3.14, 4. , 2. , 3. ])
配列のデータ型を明示的に設定する場合は、
dtype
キーワードを使用します。
In[10]: np.array([1, 2, 3, 4], dtype='float32')
Out[10]: array([ 1., 2., 3., 4.], dtype=float32)
最後に、
Python
リストとは異なり、
NumPy
配列は多次元にすることも可能です。以下のように
リストのリストを使用して多次元配列を初期化できます。
In[11]: # nested lists result in multidimensional arrays
入れ子のリストで多次元配列を作る
np.array([range(i, i + 3) for i in ...
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