Learn practical skills, build real-world projects, and advance your career
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([2,5,6],[6,3,1])
[<matplotlib.lines.Line2D at 0x1e432ec7390>]
Notebook Image
plt.plot([2,4,6,8,10],[6,3,8,2,9],label='l')
plt.xlabel('x')
plt.ylabel('y')
plt.title('title')
plt.legend()
plt.text(5,5,'text')
plt.show()
Notebook Image
import torch
t2=torch.tensor([[0,1,2],[3,4,5]])
print(t2)
print('数据={}'.format(t2))
print(t2.reshape(3,2))
print(t2+1)
print('大小={}'.format(t2.size()))
print('维度={}'.format(t2.dim()))
print('元素个数={}'.format(t2.numel()))
tensor([[0, 1, 2], [3, 4, 5]]) 数据=tensor([[0, 1, 2], [3, 4, 5]]) tensor([[0, 1], [2, 3], [4, 5]]) tensor([[1, 2, 3], [4, 5, 6]]) 大小=torch.Size([2, 3]) 维度=2 元素个数=6
t1=torch.empty(2)
t2=torch.zeros(2,2)
t3=torch.ones(2,2,2)
t4=torch.full((2,2,2,2),3.)
print(t1,"\n",t2,"\n",t3,"\n",t4) 
tensor([0., 0.]) tensor([[0., 0.], [0., 0.]]) tensor([[[1., 1.], [1., 1.]], [[1., 1.], [1., 1.]]]) tensor([[[[3., 3.], [3., 3.]], [[3., 3.], [3., 3.]]], [[[3., 3.], [3., 3.]], [[3., 3.], [3., 3.]]]])
import torch
print("1=",torch.arange(0,4,step=1))
print("2=",torch.linspace(0,5,steps=4))
print("3=",torch.logspace(0,3,steps=4))
1= tensor([0, 1, 2, 3]) 2= tensor([0.0000, 1.6667, 3.3333, 5.0000]) 3= tensor([ 1., 10., 100., 1000.])