2024-03-28 08:25:12 发布
网友
假设x是一个3x3 numpy数组,它包含以下内容:
x
import numpy as np x = np.array([[ 1., 2., 3.], [ 4., 5., 6.], [ 7., 8., 9.]])
是否有一些索引可以提供以下子数组:
可以将integer array indexing与数组元组一起使用:
>>> rows = np.array([[0, 0], ... [1, 1]], dtype=np.intp) >>> columns = np.array([[0, 1], ... [1, 2]], dtype=np.intp) >>> x[rows, columns] array([[ 1., 2.], [ 5., 6.]])
你可以用
x[:2,:2]
来解决你的问题
可以将integer array indexing与数组元组一起使用:
你可以用
来解决你的问题
相关问题 更多 >
编程相关推荐