2011-12-04 21 views

Odpowiedz

19

może po prostu dać mu listę indeksów:

indices = [1, 4, 5, 6, 7] 
zero = numpy.zeros(10) 
zero[indices] = 42 
0

Jeśli masz ndarry:

>>> x = np.zeros((3, 3, 3)) 
>>> y = [0, 9, 18] 
>>> x 
array([[[ 0., 0., 0.], 
     [ 0., 0., 0.], 
     [ 0., 0., 0.]], 

     [[ 0., 0., 0.], 
     [ 0., 0., 0.], 
     [ 0., 0., 0.]], 

     [[ 0., 0., 0.], 
     [ 0., 0., 0.], 
     [ 0., 0., 0.]]]) 
>>> np.put(x, y, 1) 
>>> x 
array([[[ 1., 0., 0.], 
     [ 0., 0., 0.], 
     [ 0., 0., 0.]], 

     [[ 1., 0., 0.], 
     [ 0., 0., 0.], 
     [ 0., 0., 0.]], 

     [[ 1., 0., 0.], 
     [ 0., 0., 0.], 
     [ 0., 0., 0.]]]) 
Powiązane problemy