张量除了有维度、大小和元素个数之外,还有元素的类型
张量有大量的初始化方法,可以和list以及numpy数组进行转换
此外张量还有大量的计算函数
如下:
from __future__ import print_function...实际值为0
print('torch.empty=',x)
y=torch.empty_like(x) #创建和input张量同阶的空张量,实际值为0
print('torch.empty_like...(n) # 生成一个0到n-1的n-1个整数的随机排列
x=torch.randperm(10)
print('torch.randperm=',x)
# 计算函数
# torch.abs(input...,out) # tensor 输出张量元素绝对值
# torch.acos(input,out) # 求反余弦
# torch.add(input,value,out) # 对每个张量元素逐个加上value...张量的形状需要匹配的
# torch.ceil(input,out) # 向上取整
# torch.clamp(input,min,max,out=None) # 将元素调整至[min,max]区间