user3139545 user3139545 - 4 years ago 96
Python Question

reshape (1000,1,17) tensor into (1000,17) tensor in numpy

Im stuck with how to transform a (1000,1,17) tensor into (1000,17) tensor.
What Im trying with sofar is

and transpose as I have seen in other answers but im not able to figure out how they work.

Im trying this (actions is my original 3d tensor)


  1. What do I need to change to get things working with 3d-2d?

  2. How can i change back from 2d-3d in the same way?

Please provide detail since a oneliner is not much help in understanding.

Answer Source

If you wanted to do it through reshape, it'd be

actions.reshape([1000, 17])

You just pass in the new shape. I have no idea why you were trying to use transpose or passing 3 and -1 as arguments. The docs are pretty clear.

Instead of reshape, it'd probably be easier to index away the length-1 dimension:

actions[:, 0]

The reverse would be

arr.reshape([1000, 1, 17])


arr[:, None]

There's also np.squeeze, which gives a view of an array with all length-1 dimensions removed, but that can remove more dimensions than you really want.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download