1

I have an complex (3x6) numpy array like this:

x = [[(1+j2) ,(2+j8), (4+j1), (6+j8), (7+j3), (8+j2)],
     [(3+j8), (5+j1), (7+j5), (3+j2), (6+j1), (3+j1)],
     [(1+j5), (5+j4), (2+j9), (9+j5), (8+j1), (4+j1)]]

I want to split them as:

x1 = [[(1+j2), (4+j1), (7+j3)],
      [(3+j8), (7+j5), (6+j1)],
      [(1+j5), (2+j9), (8+j1)]]

and

x2 = [[(2+j8), (6+j8), (8+j2)],
      [(5+j1), (3+j2), (3+j1)),
      [(5+j4), (9+j5), (4+j1)]]

I mean, I want to get a new complex numpy array by skipping each column one by one. How can I do it?

0

2 Answers 2

2

This can be achieved using array indexing.

import numpy as np

x = np.array(
    [
        [(1 + 2j), (2 + 8j), (4 + 1j), (6 + 8j), (7 + 3j), (8 + 2j)],
        [(3 + 8j), (5 + 1j), (7 + 5j), (3 + 2j), (6 + 1j), (3 + 1j)],
        [(1 + 5j), (5 + 4j), (2 + 9j), (9 + 5j), (8 + 1j), (4 + 1j)],
    ]
)
x1 = x[:, ::2]
x2 = x[:, 1::2]

Yu can find a more detailed explanation of array indexing here

Sign up to request clarification or add additional context in comments.

Comments

0

For this you can use list comprehension

Exemple:

x = [[(1+j2) ,(2+j8), (4+j1), (6+j8), (7+j3), (8+j2)],
     [(3+j8), (5+j1), (7+j5), (3+j2), (6+j1), (3+j1)],
     [(1+j5), (5+j4), (2+j9), (9+j5), (8+j1), (4+j1)]]

x1 = [ i[0:6:2] for i in x ]
x2 = [ i[1:6:2] for i in x ]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.