每日学习记录

#张量操作
import torch
import numpy as np

# #用数组构建张量
# data = [[1, 2], [3, 4]]
# a = torch.tensor(data)
#
# #用array 构造
# np_array = np.array(data)
# b = torch.from_numpy(np_array)
#
# #从另外一个张量构造
#
# c1 = torch.zeros_like(a)
# c2 = torch.ones_like(a)
# c3 = torch.rand_like(a, dtype=torch.float)
#
#
# #根据形状
# d1 = torch.ones(2, 3)
# d2 = torch.zeros(2, 3)
# d3 = torch.rand(2, 3)
#
# #tensor的属性
# print(d3.dtype)
# print(d3.shape)
# print(d3.device )

#tensor操作
#x = torch.rand(2, 3)
# if torch.cuda.is_available():
#     x = x.to('cuda') #转换到cpu 上
# print(x.device)

#print(torch.is_tensor(x)) #是否是tensor
# print(torch.is_complex(x)) #是不是复数

#print(torch.numel(x)) #返回所有元素的数目

#torch.arange(5) #左闭默认0,右开,step默认是1 返回一个1dtensor 等价与torch.arange(0,5,1)

#print(torch.range(0, 5)) #必须传 开始和结束 左闭右闭 默认数据类型不是int

#拼接
# a = torch.rand(2, 3)
# b = torch.rand(2, 3)
# c = torch.rand(2, 3)
# print(a)
# print(b)
# print(c)
# d = torch.cat([a, b, c], dim=1)
# print(d)


你可能感兴趣的:(pytorch笔记,学习,python,深度学习)