Skip to content

Instantly share code, notes, and snippets.

@indapa
Created October 2, 2012 14:59
Show Gist options
  • Save indapa/3819832 to your computer and use it in GitHub Desktop.
Save indapa/3819832 to your computer and use it in GitHub Desktop.
NumPy way to set elements of array to a value given a list of indices
import numpy as np
indices= [ 9,8,7,6,5,4,3,2,1,0]
values=np.random.rand(10).tolist()
zeros=np.zeros(10) #get an array of zeros
zeros[indices]=values # then assign the indices the values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment