2

I have two arrays with "a" which corresponds to "coordinates" in my problem and b corresponds to specific values of coordinates. I m trying to know the lines of "a" where i got all the 3 values that is in "b" as example i would like to print the line of [2,4,6] as i have them in "b" but nothing appears...there is a mistake...

import numpy as np

a = np.array([[1.,2.,3.],[4.,5.,6.],[2.,4.,6.]])

b = np.array([2,4,6,8,10])

for i in range(0,a.shape[0]):
    for j in range(0,b.shape[0]):
        if (b[j]==a[i,0] and b[j]==a[i,1]):
            print i
0

2 Answers 2

2

Try this:

for i in range(0,a.shape[0]):
    if (a[i,0] in b and a[i,1] in b and a[i,2] in b):
        print a[i]
Sign up to request clarification or add additional context in comments.

Comments

1

Since you are already using numpy this here should also work

import numpy as np

a[np.all(np.in1d(a,b).reshape(a.shape),axis=1)]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.