Deleting Masked Elements In Arrays By Index
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
Solution 1:
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)
It will delete that Index from the lists B & C, where '--' is present in List A.
Solution 2:
Try cloning the array and pop on it and replace the temp array like
a = [1,'--',3]
b = [4,5,6]
c = [7,8,9]
t=a[:]
for i in range(len(a)):
try:
value = int(a[i])
except ValueError:
t.pop(i)
b.pop(i)
c.pop(i)
a=t
print a
print b
print c
You can also use equal when you have the same symbol for masked value
a = [1,'--',3]
b = [4,5,6]
c = [7,8,9]
t=a[:]
for i in range(len(a)):
if a[i]=='--':
t.pop(i)
b.pop(i)
c.pop(i)
a=t
print a
print b
print c
Post a Comment for "Deleting Masked Elements In Arrays By Index"