python - numpy 中的数组索引

标签 python numpy

在 numpy 中是否有一种方法可以检索数组中除提供的索引项之外的所有项。

 x = 
 array([[[4, 2, 3],
    [2, 0, 1],
    [1, 3, 4]],

   [[2, 1, 2],
    [3, 2, 3],
    [3, 4, 2]],

   [[2, 4, 1],
    [0, 2, 2],
    [4, 0, 0]]])

并通过请求

x[not 1,:,:] 

你会得到

array([[[4, 2, 3],
    [2, 0, 1],
    [1, 3, 4]],

   [[2, 4, 1],
    [0, 2, 2],
    [4, 0, 0]]])

谢谢

最佳答案

In [42]: x[np.arange(x.shape[0])!=1,:,:]
Out[42]: 
array([[[4, 2, 3],
        [2, 0, 1],
        [1, 3, 4]],

       [[2, 4, 1],
        [0, 2, 2],
        [4, 0, 0]]])

关于python - numpy 中的数组索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8712332/

相关文章:

python - MATLAB 上的索引矩阵行和列,这段代码可以吗?

python - Matplotlib 的 matshow 未与网格对齐

python - 如何确定列表中的循环?

python - python会自动垃圾收集双向链表吗?

python - 使用数组条目存储数据框

numpy - 为什么 MinMaxScaler 会向图像添加线条?

python-2.7 - ValueError : The truth value of an array with more than one element is ambiguous. 使用 a.any()

python - 在matplotlib中安装Basemap时出现问题

Python SSL 连接 "EOF occurred in violation of protocol"

python - 虚拟变量,有必要标准化吗?