How to convert a 3D tensor to a tenro of lists

Hi everyone!! :smiley:

Could you help me with something?
I am trying to convert a 3D tensor that contains two layers in a tensor of lists or tuples by combining these two layers. Here is an example:

Initial 3D tensor with two layers

tensor([[[ 67.6958,  67.6958,  67.6958,  67.6958,  67.6958],
         [ 67.7049,  67.7049,  67.7049,  67.7049,  67.7049],
         [ 67.6958,  67.6958,  67.6958,  67.6958,  67.6958],
         [-66.9094, -66.9094, -66.9094, -66.9094, -66.9094],
         [-66.9094, -66.9094, -66.9094, -66.9094, -66.9094]],

        [[ 56.8013,  56.8013,  56.8013,  56.8013,  56.8013],
         [ 56.4468,  56.4468,  56.4468,  56.4468,  56.4468],
         [ 56.8013,  56.8013,  56.8013,  56.8013,  56.8013],
         [ 45.8811,  45.8811,  45.8811,  45.8811,  45.8811],
         [ 45.8811,  45.8811,  45.8811,  45.8811,  45.8811]]],
       dtype=torch.float64)

List of tuples

tensor([[67.6958, 56.8013],[67.6958, 56.8013],[-66.9094, 45.8811],...], dtype=torch.float64)

Note that it is as if I were placing one layer in front of the other and for each position of the element I would take both values and create a list of two items or a tuple with two values.

Best regards,

Matheus Santos.

Try this:

output = torch.stack((input[0].flatten(), input[1].flatten()), dim=1)

Hey! Thanks!!
I will try this :smiley: