Created
October 2, 2012 14:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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