title: Replace specific elements in NumPy array with random characters
body: <p>I have a NumPy array that looks like this:</p>
  <pre><code>array(['_', '_', '_', '_', '_', '_', '_', '_', '_', '1', '1', '_', '_',
         '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '1', '1', '1',
         '1', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
         '_', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'e', '_',
         '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
         '_', '_', '_'], dtype='&lt;U1')
  </code></pre>
  <p>I'm looking for a way to replace the <code>&quot;_&quot;</code> characters with random choices from the ascii lowercase, digits, and punctuation characters:</p>
  <pre><code>abcdefghijklmnopqrstuvwxyz0123456789!&quot;#$%&amp;\'()*+,-./:;&lt;=&gt;?@[\\]^_`{|}~
  </code></pre>
  <p>Note that I'm trying to get a different random character for each element, while preserving the non <code>&quot;_&quot;</code> characters as they are. I've tried this:</p>
  <pre><code>rng = np.random.default_rng(42)
  chars = string.ascii_lowercase+string.digits+string.punctuation
  array[array==&quot;_&quot;] = chars[rng.choice(68,1)[0]]
  </code></pre>
  <p>but it gives the same random character each time. Thanks in advance for any suggestions.</p>