正如在docs http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.delete.html,你需要使用axis
那里有选项,因为如果不提及它,它将删除扁平版本上的元素。因此,你需要这样做 -
np.delete(mytupList,indxList,axis=0).tolist()
样本运行 -
In [21]: mytupList
Out[21]: [(1, 2), (2, 3), (5, 6), (8, 9)]
In [22]: indxList
Out[22]: [1, 3]
In [23]: np.delete(mytupList,indxList).tolist() # Flattens and deletes
Out[23]: [1, 2, 5, 6, 8, 9]
In [24]: np.delete(mytupList,indxList,axis=0).tolist() # Correct usage
Out[24]: [[1, 2], [5, 6]]
要保留元组列表的格式,请使用map https://docs.python.org/2/library/functions.html#map删除后,就像这样——
map(tuple,np.delete(mytupList,indxList,axis=0))
样本运行 -
In [16]: map(tuple,np.delete(mytupList,indxList,axis=0))
Out[16]: [(1, 2), (5, 6)]