Given 2d array k = np.zeros((M, N)) and list of indices in the range 0, 1 .., M-1 of size N called places = np.random.random_integers(0, M-1, N) how do I assign 1 in each column of k in the places[i] index where i is running index.
I would like to achieve that in python compact style and without any loops
Examples:
N = 5, M =3
places= 0, 0, 1, 1, 2
Then:
k = [1, 1, 0, 0, 0
     0, 0, 1, 1, 0
     0, 0, 0, 0, 1]
 
Aucun commentaire:
Enregistrer un commentaire