I'm trying to iterate over every element of an numpy array and change its value in a semi-random manner. The reason for that is, that I'll apply that method to different arrays: I want them to be changed but I don't want them to be changed the same way.
Here is what I tried so far:
with np.nditer(smatrix, op_flags=['readwrite']) as it:
for element in it:
if element < 0:
element = element - uniform(0.1,0.2)
if 0 <= element < 0.05:
element = uniform(0.15,0.3)
elif 0.05 <= element < 1:
element = 0
elif 1 == element:
element = 1
Another possibility:
for element in np.nditer(smatrix, op_flags=['readwrite']):
if element < 0:
element = element - uniform(0.1,0.2)
if 0 <= element < 0.05:
element = uniform(0.15,0.3)
elif 0.05 <= element < 1:
element = 0
elif 1 == element:
element = 1
However, the resulting array looks exactly the same as the inital array...
I'm relatively new to programming and stuck regarding this matter for quite a while. It would be awesome if someone could give me a hint on how to solve it and ideally a short explanation. Thank you!!