0

Given a numpy array such as:

x = array([[0,  1,  2,  3],
          [ 4,  5,  6,  7],
          [ 8,  9, 10, 11],
          [12, 13, 14, 15]])

How do I form a new array composed of the first and third columns?

1 Answer 1

2

To extract the first and third columns from the array use the following syntax:

x[:,[0,2]]

This means, take all rows, selecting only columns 0 and 2. Note that indexing in numPy arrays starts at zero.

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

Comments

Your Answer

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