title: Setting numpy array to slice without any in-place operations
body: <p>How can I do this operation efficiently without any inplace operations?</p>
  
  <pre><code>n_id = np.random.choice(np.arange(2708), size=100)
  z = np.random.rand(100, 64)
  z_sparse = np.zeros((2708,64))
  z_sparse[n_id[:100]] = z
  </code></pre>
  
  <p>Essentially I want the n_id rows of z_sparse to contain z's rows, but I can't do any inplace operations because my end goal is to use this in a pytorch problem.</p>
  
  <p>One though would be to create zero rows within z precisely so that the rows of z end up in the positions n_id, but not sure how this would work efficiently.</p>
  
  <p>Essentially row 1 of <code>z</code> should be placed at row <code>n_id[0]</code> of <code>z_sparse</code>, then row 2 of <code>z</code> should be at row <code>n_id[1]</code> of <code>z_sparse</code>, and so on...</p>
  
  <p>Here's the PyTorch error jic you are curious:
  <code>RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation</code></p>