第一章基本操作-常见tensor类型

# 0:scaler  一个值 

# 1:vector  一个列

# 2:matrix 多个特征

# 3:n-dimensional tensor 

# 0:scaler
# 1:vector
# 2:matrix
# 3:n-dimensional tensor

import torch
from torch import tensor

#scaler
#通常就是一个数值

x = tensor(42.)
print(x)

print(x.dim())

print(x * 2)

print(x.item()) # 将数值进行输出

#vector
# [-5, 2, 0] 在深度学习中通常指特征, 类如词向量

y = tensor([-5, 2, 0])

print(y.dim())

print(y.size())

# Matrix 把多个特征组合在一起
M = tensor([[1, 2], [3, 4]])
print(M)

print(M.matmul(M))

# n-dimensional
D = tensor([[[1, 2], [3, 4]]])
print(D)

猜你喜欢

转载自www.cnblogs.com/my-love-is-python/p/12650451.html
今日推荐