On Wed, 23 Mar 2016 09:06 pm, Heli wrote: > Hi, > > I have a 2D numpy array like this: > > [[1,2,3,4], > [1,2,3,4], > [1,2,3,4] > [1,2,3,4]] > > Is there any fast way to convert this array to > > [[1,1,1,1], > [2,2,2,2] > [3,3,3,3] > [4,4,4,4]]
Mathematically, this is called the "transpose" of the array, and you can do that in numpy: py> import numpy as np py> arr = np.array( ... [[1,2,3,4], ... [1,2,3,4], ... [1,2,3,4], ... [1,2,3,4]]) py> arr array([[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]) py> arr.T array([[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) -- Steven -- https://mail.python.org/mailman/listinfo/python-list