user2641102
user2641102

Reputation: 3

How can I get a column from a 2D python array?

I want to know the co

import numpy as np
a = np.array([[0,0,0,2,3,0],[3,2,4,0,0,1]])

If I want to get col2 to col4, so result may be:

[[0,2,3][4,0,0]]

How can I make it? Thanks.

Upvotes: 0

Views: 94

Answers (1)

falsetru
falsetru

Reputation: 369394

>>> import numpy as np
>>> a = np.array([[0,0,0,2,3,0],[3,2,4,0,0,1]])
>>> a[:,2:5]
array([[0, 2, 3],
       [4, 0, 0]])

Upvotes: 1

Related Questions