I have an N x 2 dimensional matrix. I would like to make (2 * N) x 2 where each column is repeated. I am curious if there is a more efficient way than what I wrote below to accomplish this task.
>>> a = np.array([[1,2,3,4], [2,4,6,8]]) >>> b = np.array(zip(aT,aT)) >>> b.shape = (2*len(a[0]), 2) >>> bT array([[1, 1, 2, 2, 3, 3, 4, 4], [2, 2, 4, 4, 6, 6, 8, 8]])
The code above is slow by the numpy standard, most likely due to zip . Is there a numpy function that I can replace zip with? Or is the best way to do this at all?
source share