I can't modify the actual value of a numpy array in a loop. My code is the following :
labels_class = np.copy(labels_train)
for label in labels_class:
labels_class[label] = 1 if (label == classifier) else 0
labels_class - is just a numpy array of size N and of values [0, 39].
The value of labels_class[label] is correct(==modified) in the loop, but outside of the loop labels_classremains unchanged.
I have also tried nditer, did not work :
for label in np.nditer(labels_class, op_flags=['readwrite']):
label = 1 if (label == classifier) else 0
In the reference, it is said that "to actually modify the element of the array, x should be indexed with the ellipsis"
How do I do that? What is the syntax?
enumeratethrough the numpy array. Simply iterating over an iterable yields the elements of the iterable, not the indexes of the elements.labelyou have to use something likelabel[:]=...orlabel[...] = .... Review thenditertutorial if you want to go that route.