import torch
# 数学的な階数とPythonでの次元の対応
scalar = torch.tensor(3.14) # 0階テンソル(スカラー)
vector = torch.tensor([1, 2, 3]) # 1階テンソル(ベクトル)
matrix = torch.tensor([[1, 2],
[3, 4]]) # 2階テンソル(行列)
tensor_3d = torch.tensor([[[1,2],
[3,4]],
[[5,6],
[7,8]]]) # 3階テンソル
print(scalar.data)
print(vector.data)
print(matrix.data)
print(tensor_3d.data)
アウトプットは:
tensor(3.1400)
tensor([1, 2, 3])
tensor([[1, 2],
[3, 4]])
tensor([[[1, 2],
[3, 4]],
[[5, 6],
[7, 8]]])
Mathematics is the language with which God has written the universe.