title: Replacing values in numpy array
body: <p>I two numpy arrays, both M by N.  X contains random values.  Y contains true/false.  Array A contains indices for rows in X that need replacement, with the value -1.  I want to only replace values where Y is true.</p>
  
  <p>Here is some code to do that:</p>
  
  <pre><code>M=30
  N=40
  X = np.zeros((M,N))  # random values, but 0s work too
  Y = np.where(np.random.rand(M,N) &gt; .5, True, False)
  A=np.array([ 7,  8, 10, 13]), # in my setting, it's (1,4), not (4,)
  for i in A[0]:
      X[i][Y[A][i]==True]=-1
  </code></pre>
  
  <p>However, what I actually want is only replace some of the entries.  List B contains how many need to be replaced for each index in A.  It's already ordered so A[0][0] corresponds to B[0], etc.  Also, it's true that if A[i] = k, then the corresponding row in Y has at least k trues.</p>
  
  <pre><code>B = [1,2,1,1]
  </code></pre>
  
  <p>Then for each index i (in loop), </p>
  
  <pre><code>X[i][Y[A][i]==True][0:B[i]] = -1
  </code></pre>
  
  <p>This doesn't work.  Any ideas on a fix?</p>