x = torch.ones(2, 2, 2, requires_grad=False, dtype=torch.float64)
y = torch.zeros(2, 2, 2, requires_grad=False, dtype=torch.float64)
How can I make the result looks like
Slicing[:,:,0]
1010
1010
Slicing[:,:,1]
1010
1010
Thank you
x = torch.ones(2, 2, 2, requires_grad=False, dtype=torch.float64)
y = torch.zeros(2, 2, 2, requires_grad=False, dtype=torch.float64)
How can I make the result looks like
Slicing[:,:,0]
1010
1010
Slicing[:,:,1]
1010
1010
Thank you
Hi Miraboreasu!
If I understand your use case correctly, the following should work:
>>> import torch
>>> torch.__version__
'1.12.0'
>>> x = torch.ones (2, 2, 2, requires_grad = False, dtype = torch.float64)
>>> y = torch.zeros (2, 2, 2, requires_grad = False, dtype = torch.float64)
>>> torch.stack ((x, y), dim = 2).reshape (2, 4, 2)
tensor([[[1., 1.],
[0., 0.],
[1., 1.],
[0., 0.]],
[[1., 1.],
[0., 0.],
[1., 1.],
[0., 0.]]], dtype=torch.float64)
>>> # thus:
>>> torch.stack ((x, y), dim = 2).reshape (2, 4, 2)[:, :, 0]
tensor([[1., 0., 1., 0.],
[1., 0., 1., 0.]], dtype=torch.float64)
>>> torch.stack ((x, y), dim = 2).reshape (2, 4, 2)[:, :, 1]
tensor([[1., 0., 1., 0.],
[1., 0., 1., 0.]], dtype=torch.float64)
Best.
K. Frank