Shane Smiskol
Shane Smiskol

Reputation: 966

How can I reshape this NumPy array correctly?

I'm needing to combine the rows in this array:

array([[0.        , 1.        , 0.44768612],
       [0.34177215, 1.        , 0.        ]])

So that the output is:

array([[0., 0.34177215], [1., 1.], [0.44768612, 0.])

But for some reason, I can't figure it out with the reshape function. Any help would be appreciated.

Upvotes: 0

Views: 60

Answers (2)

YoniChechik
YoniChechik

Reputation: 1537

if array is A, just do A.T...

Upvotes: 2

David Buck
David Buck

Reputation: 3843

If x is your array, x.T will transpose it:

array([[0.        , 1.        , 0.44768612],
       [0.34177215, 1.        , 0.        ]])

becomes

array([[0.        , 0.34177215],
       [1.        , 1.        ],
       [0.44768612, 0.        ]])

Upvotes: 2

Related Questions