hoe to define 3d tensor

Solutions on MaxInterview for hoe to define 3d tensor by the best coders in the world

showing results for - "hoe to define 3d tensor"
Joris
28 Nov 2016
1# torch.tensor(data) creates a torch.Tensor object with the given data.
2V_data = [1., 2., 3.]
3V = torch.tensor(V_data)
4print(V)
5
6# Creates a matrix
7M_data = [[1., 2., 3.], [4., 5., 6]]
8M = torch.tensor(M_data)
9print(M)
10
11# Create a 3D tensor of size 2x2x2.
12T_data = [[[1., 2.], [3., 4.]],
13          [[5., 6.], [7., 8.]]]
14T = torch.tensor(T_data)
15print(T)
16