numpy - How to find the set of indices where two vectors have equal elements in Python -


i have 2 vectors in python: predictions , labels. find out set of indices these 2 vectors have equal elements. example, lets vectors are:

predictions = [4, 2, 5, 8, 3, 4, 2, 2]       labels = [4, 3, 4, 8, 2, 2, 1, 2] 

so set of indices 2 vectors have equal elements be:

indices = [0, 3, 7] 

how can in python? without using for-loops etc. there built-in function example in numpy?

thank help!

this 1 way of doing numpy:

np.where(np.equal(predictions, labels)) 

which equivalent to:

np.equal(predictions, labels).nonzero() 

it return single element tuple though, actual array, add [0] in:

np.equal(predictions, labels).nonzero()[0] 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -