Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)
edited by

How do you think I can get the intersection of the below-given array?

a=np.array([[[[0,0],[0,1]],[[1,1],[1,1]]], 

            [[[1,0],[1,1]],[[0,1],[1,1]]]])

This is the expected output:

array([[[0, 0],

        [0, 1]],

        [[0, 1],

         [1, 1]]]

1 Answer

0 votes
by (36.8k points)

You can use the below code:

a[0] & a[1]

OR

np.logical_and(a[0], a[1]).astype(int)

In general, if length of varibale 'a' is not defined, you can use:

np.logical_and.reduce(a).astype(int)

 Do check out data science with python certification to understand from scratch

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...