按索引删除数组中的掩码元素 [英] Deleting masked elements in arrays by index

查看:69
本文介绍了按索引删除数组中的掩码元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个数组,其中一个包含基于某些条件的掩码值:

I have three arrays and one contains masked values based off some condition:

a = numpy.ma.MaskedArray(other_array, condition)

(最初,我使用掩码数组,因为我的条件是一个变量,它使绘制其他数据集变得容易得多,以保持数组固定长度.现在,我导出数据以供其他程序编写,而不由我编写,并且无法处理'-')

(Initially I used masked arrays because my condition is a variable and it made plotting a lot easier with other data sets to keep my arrays fixed lengths. Now I'm exporting my data to be analysed by other program not written by me, and it can't handle '--')

所以我的数组的格式为:

So my arrays have the form:

a = [1,--,3]
b = [4,5,6]
c = [7,8,9]

我要遍历a,标识包含掩码值'-'的a的任何索引,然后从所有数组中删除该索引:

I want to iterate through a, identify any index of a that contains a masked value '--', and then delete that index from all arrays:

a = [1,3]
b = [4,6]
c = [7,9]

实际上,a和b都很长,并且被屏蔽的索引没有规则地隔开.

In reality, a b and c are very long, and the masked indices aren't regularly spaced.

谢谢!

推荐答案

如果只有3个列表,则可以使用 pop() 函数从中删除索引清单B& C.将索引传递到 pop() ,在列表A中它为-".

If there are only 3 lists, you can use pop() function to delete the indexes from List B & C. Pass the Index to pop() where it is '--' in List A.

for i in range(len(a)):
    if numpy.ma.is_masked(a[i]):
        b.pop(i)
        c.pop(i)

它将从列表B&中删除该索引. C,其中-"出现在列表A中.

It will delete that Index from the lists B & C, where '--' is present in List A.

这篇关于按索引删除数组中的掩码元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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