I noticed a (to me) very strange behavior, I don't understand:
I got a list and an numpy array both with binary values and I want to check the true positives (both==1 at the same time).
import numpy as np
a = [0,0,1,1]
b = np.array([1,0,1,0])
for a,b in zip(a,b):
if a==1 and b==1:
zip did not change your list. You lost the initial references to your lists when you assigned the name
b to the loop variables in:
for a, b in zip(a,b): # ^ ^
A simple fix is to change those names to say,
for i, j in zip(a,b):
One thing to bear in mind when using Python is that names are bound to objects, and therefore can be unbound or even rebound. No name is for keeps. Once you change the object a name is referencing like you did, the name starts to reference the new object.
On another note,
for loops assign the objects from the iterable to the name(s) provided, similar to a regular assignment, but with repetitions. So the values you get for
b at the end of the
for loop are those of the last assignment done in the last iteration.
Do bear these in mind.