# Reshape tensor with RGB value

In following program “tensor_m” with torch.Size([1, 3, 3, 3]) reshape to “tensor_n” with torch.Size([1, 9, 3]). Assume “tensor_m” of 3 RGB channel with 3x3 value with first value of each channel 0.63, 0.22 and 0.77 respectively.

I need “tensor_n” with reshape as RGB value. For an example first value should be [ 0.63, 0.22, 0.77 ] and so on. (first value of each channel instead of each channel converted in series as shown in output)

``````m = torch.rand(3,3,3)
m=m.unsqueeze(0)
print(m)
print(m.shape)
n=torch.reshape(m,[1,9,3])
print(n)

Output: tensor([[[[0.6372, 0.9886, 0.0787],
[0.1122, 0.5088, 0.9846],
[0.7976, 0.7544, 0.9155]],

[[0.2244, 0.4629, 0.4907],
[0.5833, 0.3484, 0.0845],
[0.8927, 0.8919, 0.5495]],

[[0.7770, 0.3146, 0.4091],
[0.6119, 0.8719, 0.4748],
[0.9458, 0.8806, 0.9648]]]])
torch.Size([1, 3, 3, 3])
tensor([[[0.6372, 0.9886, 0.0787],
[0.1122, 0.5088, 0.9846],
[0.7976, 0.7544, 0.9155],
[0.2244, 0.4629, 0.4907],
[0.5833, 0.3484, 0.0845],
[0.8927, 0.8919, 0.5495],
[0.7770, 0.3146, 0.4091],
[0.6119, 0.8719, 0.4748],
[0.9458, 0.8806, 0.9648]]])``````