LoginSignup
0
0

More than 3 years have passed since last update.

[python] numpyのreshapeメソッドの-1の意味

Last updated at Posted at 2020-07-09

numpyのreshapeは数値を指定することで、多次元配列を変形するメソッドであるが、-1を指定すると具体値を指定しなくてもメソッドが自動的にもう片方の数値から適当な数値を決めてくれる。

要素数3のリストを1行3列の行列にする例
arr = [1,2,3]
print(len(arr))
# 3

narr1 = np.array(arr).reshape(1,3) 
print(narr1.shape)
# (1, 3)

narr2 = np.array(arr).reshape(1,-1)
print(narr2.shape)
# (1, 3)
0
0
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
0