形状
本資料では、配列やテンソルのshape属性が返す値のことを指す。軸の向きに対する長さを高次の軸から順に並べた情報が得られる。
code:shape01.py
import numpy as np
import torch as pt
print('# 配列型のshape')
x1 = np.random.random(2, 3) # (2, 3)の乱数配列
print(x1, x1.shape)
y1 = np.random.random(2, 3, 4) # (2, 3, 4)の乱数配列
print(y1, y1.shape)
print('# テンソル型のshape')
x2 = pt.tensor(x1)
y2 = pt.tensor(y1)
print(y2, y2.shape)
print(y2, y2.shape)
参考:shape属性【numpy】、shape属性【torch】