一个开源的机器学习框架,加速了从研究原型到生产部署的路径 。!pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple
import torchimport numpy as np
Basics就像Tensorflow一样,我们也将继续在PyTorch中玩转Tensors 。
从数据(列表)中创建张量data = https://www.huyubaike.com/biancheng/[[1, 2],[3, 4]]tensors = torch.tensor(data)
tensors
tensor([[1, 2],[3, 4]])
从NumPy创建np_array = np.arange(10)tensor_np = torch.from_numpy(np_array)
tensor_np
tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=torch.int32)
形状、ndim和dtype这与我们在《Numpy教程--第1天》中看到的相同 。
tensor_np.shape
torch.Size([10])
tensor_np.ndim
1
tensor_np.dtype
torch.int32
张量操作(Tensor_Operations)ten1 = torch.tensor([1,2,3])ten2 = torch.tensor([4,5,6])ten1+ten2
tensor([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*10
tensor([10, 20, 30])
深度学习中非常重要的操作--矩阵乘法
经验总结扩展阅读
- 免疫系统 断食3天能重启人体免疫系统?美国研究发布结论,建议早了解
- 咳咳了解是什么意思?
- 王者荣耀鲁班七号皮肤了解?
- 王者荣耀后羿皮肤了解?
- 5大丰胸水果丰胸其实并不难,只需要了解这一点?
- 如何了解现金流量表?
- 充分了解门店周边客户的消费特征有什么好处?
- 进行电话销售时如何耐心了解客户的需求?
- 关于生态农业要了解哪些?
- 最先了解引起仔猪下痢的原因是什么?