nechi
nechi

Reputation: 102

reshape a numpy ndarray python3

Let's say that I have an ndarray of shape (10 x 1024 x 2) presenting 10 vectors of 1024 complex values each value has a real and imaginary parts. and I want to reshape this array to (10 x 2 x 1024) meaning 10 vectors each vector has two arrays one for real parts and the other for imaginary.

I try with reshape() and vstack() but, the data looses the right order and I am afraid if I use swapaxes(), I can encounter memory problems later since the data is actually bigger.

Anyone have an idea about how should I fix this issue?

Upvotes: 0

Views: 73

Answers (1)

asymptote
asymptote

Reputation: 1402

How about using transpose:

a = np.random.rand(10, 1024, 2)
a_t = a.transpose(0,2,1) #shape is (10, 2, 1024)

Upvotes: 2

Related Questions