title: Changing individual elements of numpy array based on its value
body: <p>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.</p>
  
  <p>Here is what I tried so far:</p>
  
  <pre><code>with np.nditer(smatrix, op_flags=['readwrite']) as it:
      for element in it:
          if element &lt; 0:
              element = element - uniform(0.1,0.2)
          if 0 &lt;= element &lt; 0.05:
              element = uniform(0.15,0.3)
          elif 0.05 &lt;= element &lt; 1:
              element = 0
          elif 1 == element:
              element = 1
  </code></pre>
  
  <p>Another possibility:</p>
  
  <pre><code>for element in np.nditer(smatrix, op_flags=['readwrite']):
      if element &lt; 0:
          element = element - uniform(0.1,0.2)
      if 0 &lt;= element &lt; 0.05:
          element = uniform(0.15,0.3)
      elif 0.05 &lt;= element &lt; 1:
          element = 0
      elif 1 == element:
          element = 1
  </code></pre>
  
  <p>However, the resulting array looks exactly the same as the inital array...</p>
  
  <p>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!!</p>