简体   繁体   中英

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.

>>> 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]])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM