title: How to implement this for loop more elegant with numpy?
body: <p>this is some snippet of my code. Can someone the appropriate 
  way to do this. Some fancy NumPy trick?</p>
  
  <pre><code>q_val = np.random.rand(5,3) 
  
  action = np.ones((5,1),int)
  to_set = np.ones((5,1),int)
  for x in range(5):
       q_val[x][action[x]] -= to_set[x]
  </code></pre>
  
  <p>This is how I instantiate the values</p>
  
  <pre><code>q_val = np.random.rand(5,3) //lets say the middel of randome
  q_val = array([[0.93373647, 0.        , 0.14962181],//get only zeroes
         [0.67909199, 0.        , 0.07462584],
         [0.05696713, 0.        , 0.03221326],
         [0.78209394, 0.        , 0.58312439],
         [0.09217555, 0.        , 0.17876316]])                           
  action = np.ones((5,1),int)
  action = &gt;&gt;&gt; action
  array([[1],
         [1],
         [1],
         [1],
         [1]])
  
  to_set = np.ones((5,1),int)
  to_set = array([[1],
         [1],
         [1],
         [1],
         [1]])
  </code></pre>
  
  <p>This what I will change</p>
  
  <pre><code>for x in range(5):
       q_val[x][action[x]] -= to_set[x]
  </code></pre>
  
  <p>This what I will get</p>
  
  <pre><code>array([[ 0.93373647, -1.        ,  0.14962181],
         [ 0.67909199, -1.        ,  0.07462584],
         [ 0.05696713, -1.        ,  0.03221326],
         [ 0.78209394, -1.        ,  0.58312439],
         [ 0.09217555, -1.        ,  0.17876316]])
  </code></pre>
  
  <p>I am sure there is some fancy method to do this in one of line.
  Can someone help?</p>