StevenJokes
1.
x = torch.arange(12, dtype=torch.float32).reshape((3,4))
y = torch.tensor([[2.0, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])
x,y,x == y,x < y,x > y
(tensor([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]]),
tensor([[2., 1., 4., 3.],
[1., 2., 3., 4.],
[4., 3., 2., 1.]]),
tensor([[False, True, False, True],
[False, False, False, False],
[False, False, False, False]]),
tensor([[ True, False, True, False],
[False, False, False, False],
[False, False, False, False]]),
tensor([[False, False, False, False],
[ True, True, True, True],
[ True, True, True, True]]))
2.
a = torch.arange(1, 6, dtype =torch.float32).reshape((5, 1))
b = torch.arange(1, 3).reshape((1, 2))
a, b
(tensor([[1],
[2],
[3],
[4],
[5]]),
tensor([[1, 2]]))
a + b
tensor([[2., 3.],
[3., 4.],
[4., 5.],
[5., 6.],
[6., 7.]])
a - b
tensor([[ 0., -1.],
[ 1., 0.],
[ 2., 1.],
[ 3., 2.],
[ 4., 3.]])
a * b
tensor([[1.0000, 0.5000],
[2.0000, 1.0000],
[3.0000, 1.5000],
[4.0000, 2.0000],
[5.0000, 2.5000]])
a / b
tensor([[1, 0],
[2, 1],
[3, 1],
[4, 2],
[5, 2]])
a // b
tensor([[1., 0.],
[2., 1.],
[3., 1.],
[4., 2.],
[5., 2.]])
a \ b
File “” , line 1 a \ b ^ SyntaxError : unexpected character after line continuation character
a ** b
tensor([[ 1., 1.],
[ 2., 4.],
[ 3., 9.],
[ 4., 16.],
[ 5., 25.]])