numpy删除以零开头的所有行
我有2D numpy数组,我想删除以某些值开头的所有行,然后将所有以其他值开头的行保持在
a1 = np.array([[ 0, 1, 2, 3, 4],
[ 5, 6, 0, 8, 0],
[10, 11, 12, 13, 14],
[ 0, 16, 17, 18, 19],
[20, 21, 22, 0, 24]])
第一步之后的
a2 = ([[ 5, 6, 0, 8, 0],
[10, 11, 12, 13, 14],
[20, 21, 22, 0, 24]])
新数组中,然后将所有行开始。
a3 = ([[10, 11, 12, 13, 14]])
I have 2D Numpy array, I would like to delete all rows that start with certain value let say (0), then keep all rows that start with other value let say (10) into new array
a1 = np.array([[ 0, 1, 2, 3, 4],
[ 5, 6, 0, 8, 0],
[10, 11, 12, 13, 14],
[ 0, 16, 17, 18, 19],
[20, 21, 22, 0, 24]])
after first step
a2 = ([[ 5, 6, 0, 8, 0],
[10, 11, 12, 13, 14],
[20, 21, 22, 0, 24]])
last step
a3 = ([[10, 11, 12, 13, 14]])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用以下蒙版来实现此目的:
You can achieve this with the following masks:
您可以使用np.logical_not方法来创建要删除的行的条件。
'''
'''
you can use the np.logical_not method to create the conditions for the rows you want to remove.
'''
'''