python - Numpy array, specifiyng what elements to return -


say have following 5x5 numpy array called a

array([[6, 7, 7, 7, 8],        [4, 2, 5, 5, 9],        [1, 2, 4, 7, 4],        [0, 7, 3, 6, 8],        [4, 9, 6, 1, 6]]) 

and 5x5 array called f

array([[1,0,0,0,0],        [1,0,0,0,0],        [1,0,0,0,0],        [1,0,0,0,0],        [0,0,0,0,0]]) 

i've been trying use np.copyto, can't wrap head around why not working/how works.valueerror: not broadcast input array shape (5,5) shape (2)

is there easy way values of matching integers have corresponding 1 in f when laid on a? e.i return, 6,4,1,0

you can little trick: a[f==1]

in [8]:  a[f==1] out[8]: array([6, 4, 1, 0]) 

check out boolean indexing


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -