Reputation:
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?
Upvotes: 0
Views: 76
Reputation:
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.
Upvotes: 2