How to sort the matrix in a specific dimension in Ipython?

ipython

#1

I am currently studying about sorting of matrix in python but I am able to perform the sorting only row wise. Want to know how to perform sorting column wise.

arr=np.random.randn(5,3)
arr
array([[ 1.38353476,  1.93488245, -0.82519646],
       [ 1.55524243, -0.55439432, -0.51262486],
       [ 0.33529077, -0.86272146,  0.07555946],
       [-1.00505909, -0.32670848, -0.1438106 ],
       [ 0.15357458, -1.90376821, -1.27153489]])
arr.sort()
arr
array([[-0.82519646,  1.38353476,  1.93488245],
       [-0.55439432, -0.51262486,  1.55524243],
       [-0.86272146,  0.07555946,  0.33529077],
       [-1.00505909, -0.32670848, -0.1438106 ],
       [-1.90376821, -1.27153489,  0.15357458]])

#2

@sid100158
you can perform sorting along any axis by specifying the axis in the function for example for column wise sorting you can use the function like

arr.sort(1)

it will sort the matrix column-wise and the default value of the function is zero which means sorting row wise.

Hope this helps!

Regards,
Hinduja