0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

numpy その1

0
Posted at

ndarray n次元のアレイ

1
import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)
1の実行結果
[[1 2 3]
 [4 5 6]]

アレイのデータタイプを指定できる。
何ビットの型を利用するか。
ビット数を指定することで確保するメモリ量を調整することができます。

2
import numpy as np

a = [1, 2, 3]

ndarray = np.array(a, dtype='float32')
print(ndarray.dtype)

ndarray = np.array(a, dtype='int32')
print(ndarray.dtype)
2の実行結果
float32
int16

データタイプの変更

3
import numpy as np

a = [1, 2, 3]

arr = np.array(a, dtype='int32')
arr2 = arr.astype('float32')

print(arr2.dtype)
2の実行結果
float32
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?