0

I have such a python numpy array;

[[-0.17433028 -0.20116786 -0.17599097 -0.1907735   0.27599955 -0.16071874]
 [-0.21809219 -0.20256139 -0.15900832 -0.18323743 -0.26910328  0.78731642]]

How can I reshape the array as the following?

[[-0.17433028, -0.21809219], [-0.20116786, -0.20256139], [-0.17599097, -0.15900832], [-0.1907735, -0.18323743], [0.27599955, -0.26910328], [-0.16071874, 0.78731642]]

2 Answers 2

3

You want to use the transpose method:

>>> arr = np.array([[-0.17433028, -0.20116786, -0.17599097, -0.1907735, 0.27599955, -0.16071874], [-0.21809219, -0.20256139, -0.15900832, -0.18323743, -0.26910328,  0.78731642]])

>>> arr.transpose()
array([[-0.17433028, -0.21809219],
       [-0.20116786, -0.20256139],
       [-0.17599097, -0.15900832],
       [-0.1907735 , -0.18323743],
       [ 0.27599955, -0.26910328],
       [-0.16071874,  0.78731642]])
Sign up to request clarification or add additional context in comments.

1 Comment

A shortcut would be to use the T property for NumPy arrays: arr.T.
1

This looks like you want the transpose of the matrix. You can do this with numpy.transpose(array).

1 Comment

A shortcut would be to use the T property for NumPy arrays: array.T.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.