python - how to assign a value to numpy array in specific rows and cols -


i want assign array specific (row, col) value 1

here code:

fl = np.zeros((5, 3)) labels = np.random.random_integers(0, 2, (5, 1)) in range(5):     fl[i, labels[i]] = 1 

is there shortcut process?

here way it:

import numpy np fl = np.zeros((5, 3)) labels = np.random.random_integers(0, 2, 5) fl[range(0, 5), labels] = 1 

and produce output:

enter image description here


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -