了解Pytorch|Get Started with PyTorch

一个开源的机器学习框架,加速了从研究原型到生产部署的路径 。!pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple
import torchimport numpy as npBasics就像Tensorflow一样 , 我们也将继续在PyTorch中玩转Tensors 。
从数据(列表)中创建张量data = https://www.huyubaike.com/biancheng/[[1, 2],[3, 4]]tensors = torch.tensor(data)tensorstensor([[1, 2],[3, 4]])
从NumPy创建np_array = np.arange(10)tensor_np = torch.from_numpy(np_array)tensor_nptensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=torch.int32)
形状、ndim和dtype这与我们在《Numpy教程--第1天》中看到的相同 。
tensor_np.shapetorch.Size([10])
tensor_np.ndim1
tensor_np.dtypetorch.int32
张量操作(Tensor_Operations)ten1 = torch.tensor([1,2,3])ten2 = torch.tensor([4,5,6])ten1+ten2tensor([5, 7, 9])
你可以使用+torch.add来执行张量添加 。
torch.sub(ten2,ten1)tensor([3, 3, 3])
torch.add(ten1,ten2)tensor([5, 7, 9])
torch.subtract(ten2,ten1)tensor([3, 3, 3])
你可以使用-torch.sub来执行张量添加 。
ten1*10tensor([10, 20, 30])
深度学习中非常重要的操作--矩阵乘法

    推荐阅读