title: Numpy: how to assign values to individual elements of multidimensional arrays?
body: <p>I'm working with 3-dimensional arrays (for the purpose of this example you can imagine they represent the RGB values at X, Y coordinates of the screen).</p>
  
  <pre><code>&gt;&gt;&gt; import numpy as np
  &gt;&gt;&gt; a = np.floor(10 * np.random.random((2, 2, 3)))
  &gt;&gt;&gt; a
  array([[[ 7.,  3.,  1.],
          [ 9.,  6.,  9.]],
  
         [[ 4.,  6.,  8.],
          [ 8.,  1.,  1.]]])
  </code></pre>
  
  <p>What I would like to do, is to <strong>set to an arbitrary value the G channel for those pixels whose G channel is already below 5</strong>. I can manage to isolate the pixel I am interested in using:</p>
  
  <pre><code>&gt;&gt;&gt; a[np.where(a[:, :, 1] &lt; 5)]
  array([[ 7.,  3.,  1.],
         [ 8.,  1.,  1.]])
  </code></pre>
  
  <p>but I am struggling to understand how to assign a new value to the G channel only. I tried:</p>
  
  <pre><code>&gt;&gt;&gt; a[np.where(a[:, :, 1] &lt; 5)][1] = 9
  &gt;&gt;&gt; a
  array([[[ 7.,  3.,  1.],
          [ 9.,  6.,  9.]],
  
         [[ 4.,  6.,  8.],
          [ 8.,  1.,  1.]]])
  </code></pre>
  
  <p>...but it seems not to produce any effect. I also tried:</p>
  
  <pre><code>&gt;&gt;&gt; a[np.where(a[:, :, 1] &lt; 5), 1] = 9
  &gt;&gt;&gt; a
  array([[[ 7.,  3.,  1.],
          [ 9.,  9.,  9.]],
  
         [[ 4.,  6.,  8.],
          [ 9.,  9.,  9.]]])
  </code></pre>
  
  <p>...(failing to understand what is happening). Finally I tried:</p>
  
  <pre><code>&gt;&gt;&gt; a[np.where(a[:, :, 1] &lt; 5)][:, 1] = 9
  &gt;&gt;&gt; a
  array([[[ 7.,  3.,  1.],
          [ 9.,  6.,  9.]],
  
         [[ 4.,  6.,  8.],
          [ 8.,  1.,  1.]]])
  </code></pre>
  
  <p>I suspect I am missing something fundamental on how NumPy works (this is the first time I use the library). I would appreciate some help in how to achieve what I want as well as some explanation on what happened with my previous attempts.</p>
  
  <p>Many thanks in advance for your help and expertise!</p>
  
  <p><strong>EDIT</strong>: The outcome I would like to get is:</p>
  
  <pre><code>&gt;&gt;&gt; a
  array([[[ 7.,  9.,  1.],     # changed the second number here
          [ 9.,  6.,  9.]],
  
         [[ 4.,  6.,  8.],
          [ 8.,  9.,  1.]]])   # changed the second number here
  </code></pre>