I have 2d numpy array:
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>]
.
Example -
import numpy as np
a = np.array([[1,2,3,4],
[4,5,6,7]])
print(a[:,2:])
>>> [[3 4]
[6 7]]
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.