如何从numpy ndarray删除特定值 [英] How to delete specific values from numpy ndarray

查看:1524
本文介绍了如何从numpy ndarray删除特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似numpy的ndarray:

I have a numpy ndarray that looks like:

[[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[225 224 228],
[163 164 174],
[205 212 229],
[116 130 153],
[ 81 101 132],
[ 34  56  92],
[  2  16  35],
[ 33  44  64],
[ 38  49  71],
[ 63  75  99],
[ 76  88 116],
[ 45  62  95],
[ 29  50  88],
[ 18  40  82],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0]]

我想删除所有零元素,即[0,0,0].我该怎么办?

I want to delete all the zero elements i.e. [0,0,0]. How can I do this?

推荐答案

您可以使用 np.delete() np.where()以获得满足条件的元素,如下所示:

You can use np.delete() and np.where() to get the elements where the condition is satisfied as :

del_arr = np.delete(arr, np.where(arr == [0, 0, 0]), axis=0)
print del_arr

这篇关于如何从numpy ndarray删除特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆