-1

I have a numpy array of 3*k elements, where k is an integer. For instance, for k=3 I have the array A. Below, x, y, and z are filled by drawing elements from A as shown in the following example:

import numpy as np

A = np.arange(9)
>> array([0, 1, 2, 3, 4, 5, 6, 7, 8])

x = A[0::3]
>> array([0, 3, 6])

y = A[1::3]
array([1, 4, 7])

z = A[2::3]
>> array([2, 5, 8])

Now, I want to use x, y, and z so as to reconstruct A. Is there any convenient way of doing this without using for loops?

nullgeppetto
  • 539
  • 1
  • 8
  • 25

1 Answers1

1

You can do

np.array([x,y,z]).T.reshape(-1)
Umang Gupta
  • 15,022
  • 6
  • 48
  • 66