Back
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]]]])
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]]]
array([[[0, 0],
[0, 1]],
[[0, 1],
[1, 1]]]
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