Something strange is happening here (strange to me at least). I am trying to pop 'nan' values from one list and the corresponding values from another list. I was informed that you cannot pop from a list that is being enumerated, so I made a temporary list.
import numpy as np
a=[]
b=[]
for i in range(0,100): #alternating list of ints and nan
if i/2. == i/2:
a.append(i)
else:
a.append(np.mean([])) #the only way I know how to make nan
b.append(i*100)
atemp=a
print(len(a),len(atemp))
for i,v in enumerate(atemp):
if np.isnan(v):
a.pop(i)
b.pop(i)
print(len(a),len(atemp))
A couple things are happening that I don't understand:
1) it appears to be popping nans from atemp AND a, even though I am only telling it a.pop(i) and not atemp.pop(i). Is there some sort of function overloading or something equating a and atemp that I don't see? How do I make them entirely separate lists (i.e. only pop from a and not atemp?
2) it is not popping all nan's and the for loop has to be repeated multiple times to pop all nan's