[英]Extracting columns from a 2d numpy array
I have 2d numpy array:我有二维 numpy 数组:
import numpy as np
a = np.array([[1,2,3,4],
[4,5,6,7]])
How can I extract the following array?如何提取以下数组?
result = array([[3,4],
[6,7]]
That is called slicing
, you can use <array>[<row indexes>,<column indexes>]
.这称为
slicing
,您可以使用<array>[<row indexes>,<column indexes>]
。
Example -例子 -
import numpy as np
a = np.array([[1,2,3,4],
[4,5,6,7]])
print(a[:,2:])
>>> [[3 4]
[6 7]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.