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 3 years have passed since last update.

NumPyの操作方法

Posted at

https://www.udemy.com/course/ds_for_python/
をやってるなかで、コマンド忘れそうなので

import
import numpy as np

#flatten()

flatten
array1=np.array([[1,2,3],[4,5,6],[7,8,9]])
array1.flatten()

##結果
array([1, 2, 3, 4, 5, 6, 7, 8, 9])

#squeeze

squeeze
array1=np.array([[1,2,3]])
array1.shape

(1, 3)

squeeze
np.squeeze(array1)

(3,)

次元を減らす。

#expand_dims

expand_dims
ndarray1=np.array([1,2,3])
ndarray1.shape
expand_axis=np.expand_dims(ndarray1, axis=-1)
expand_axis.shape
expand_axis
(3,)

(3, 1)

array([[1],
       [2],
       [3]])

逆に、次元を増やす。
axisの引数で増やす場所が変わる。

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?