LoginSignup
10
7

More than 5 years have passed since last update.

Pythonで配列のサイズ(numpy.shape)

Last updated at Posted at 2017-12-19

numpyを使うことを前提にしています。

デバックなどで、定義してある配列が何行何列なのか知りたいときが結構あります。
このときは.shapeを用いてば良いです。

checkarray.py
import numpy as np
#5×3の行列を作成(要素は全て0)
a=np.array([[0]*3 for i in range(5)])
print("a="+str(a))
print(a.shape)

a=[[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]]
(5, 3)
と出力されるはずです

10
7
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
10
7