如何从np中删除每个元素。数组来获取没有这个合适元素的数组?

时间:2016-11-04 09:08:02

标签: python arrays numpy

我有一个numpy-array

   X_test =  [array([1,2]), array([3,4]), array([5,6]), array([7,8]), array([9,10]), array([11,12])]

我会删除每一行以获得一个新数组:

[array([3,4]), array([5,6]), array([7,8]), array([9,10]), array([11,12])]
[array([1,2]), array([5,6]), array([7,8]), array([9,10]), array([11,12])]
[array([1,2]), array([3,4]), array([7,8]), array([9,10]), array([11,12])]
[array([1,2]), array([3,4]), array([5,6]), array([9,10]), array([11,12])]
[array([1,2]), array([3,4]), array([5,6]), array([7,8]), array([11,12])]
[array([1,2]), array([3,4]), array([5,6]), array([7,8]), array([9,10])]

我曾尝试过这样的阵列:

for i in range(len(X_test)):
    np.delete(X_test, i)
    print X_test

1 个答案:

答案 0 :(得分:0)

[X_test[:i] + X_test[i+1:] for i in range(len(X_test))]

为您提供包含所需元素的列表