dimanche 14 février 2021

Having issues appending values to numpy array

I am having an issue appending the correct values to a python array. i have a code snipped right here:

p = np.zeros(8)
h = [2,3,7,4,5,6,1,9]
h = np.array(h)
for i in (0,7):
    if (h[i] >= 5):
        p[i]=1
    else:
        p[i]=3
p

The output that I'm expecting is [3,3,1,3,1,1,3,1], but for some reason I keep getting [3., 0., 0., 0., 0., 0., 0., 1.]. It seems like the first and last array values are read and appending correctly, but all the other elements are not. I am sure that it's just some silly error, but I just can't seem to find it.

Aucun commentaire:

Enregistrer un commentaire