首页 > 编程知识 正文

张量,pytorch查看张量维度

时间:2023-05-04 10:26:39 阅读:184699 作者:559

import torcha = torch.randn(2, 2)print(a)print(a.shape) #张量的形状 (沿每个轴的长度)print(len(a)) print(a.numel()) #张量中元素的总数

 reshape(x,y,z)

import torchb=torch.arange(12)print(b)print("----")print(b.reshape(3,4))print(b.reshape(-1,4))print(b.reshape(3,-1))print(b.reshape(2,2,3)) print(b.reshape(2,2,-1)) #

print(b.reshape(2,3,2)) #大空行分开2行,每行中有三行,有2列

 

 

 

 

 

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。