python - slicing column in numpy array and creating new matrix -


i have concatenate columns of numpy matrix create new matrix. have 2 codes. 1 working fine. other giving me trouble. 1 working fine is

x = np.array(range(24)) x = x.reshape((3,4,2)) y = np.array(range(100,124)) y = y.reshape((3,4,2)) z = np.concatenate((x,y)) 

now result 6,4,2 if axis =0 si 3,8,2 if axis=1 , 3,4,4 if axis=2. @ code:

a=np.array(([1,2,3],[4,5,6],[7,8,9]) b=a[:,1] # took 1 column c=a[:,0] # again took 1 column d=np.concatenate((b,c)) 

if provide axis=0 result 1x6. if provide axis=1 again 1,6. want in 1 case 1,6 in 3,2. ie

[2,1],[5,4],[8,7] 

and in 2,3 ie

[2,5,8],[1,4,7] 

i wondering why concatenate not working me?

use vstack

>>> import numpy np >>> a=np.array(([1,2,3],[4,5,6],[7,8,9])) >>> b=a[:,1] # took 1 column >>> c=a[:,0] # again took 1 column >>> np.vstack((b,c)) array([[2, 5, 8],        [1, 4, 7]]) 

use np.transpose if necessary


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -