1

I would like to control how array.reshape() populates the new array. For example

a = np.arange(12).reshape(3,4)
## array([[ 0,  1,  2,  3],
##   [ 4,  5,  6,  7],
##   [ 8,  9, 10, 11]]) 

but what I would like to be able to is populate the array columnwise with something like:

a = np.arange(9).reshape(3,3, 'columnwise')
## array([[ 0,  3,  6,  9],
##   [ 1,  4,  7,  10],
##   [ 2,  5, 8, 11]]) 
0

3 Answers 3

2

Use np.transpose.

import numpy as np

print(np.arange(9).reshape(3,3).transpose())

Output:

[[0 3 6]
 [1 4 7]
 [2 5 8]]
Sign up to request clarification or add additional context in comments.

Comments

0
In [22]:  np.arange(12).reshape(3,4, order='F')                                                        
Out[22]: 
array([[ 0,  3,  6,  9],
       [ 1,  4,  7, 10],
       [ 2,  5,  8, 11]])

Comments

0

If you take a transpose of the original matrix, you will get your desired effect.

import numpy as np
a = np.arange(6).reshape(3,3).tranpose()

OR

a = np.arange(6).reshape(3,3).T

Comments

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.