-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?

0

1 Answer 1

1

You can do

np.array([x,y,z]).T.reshape(-1)
Sign up to request clarification or add additional context in comments.

5 Comments

It works like a charm! Many thanks.
Feel free to accept the answer..if you like :)
Sure, but you answered too quickly... So you need to wait 5 more minutes :)
oh sorry! Didnt know that. One more thing, can you check for some other value of k (other than 3)
Yeah, it seems that it works for any integer k.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.