Solution to How to find rows of A that contain elements of each row of B
This commit is contained in:
@@ -2127,7 +2127,7 @@
|
|||||||
"B = np.random.randint(0,5,(2,2))\n",
|
"B = np.random.randint(0,5,(2,2))\n",
|
||||||
"\n",
|
"\n",
|
||||||
"C = (A[..., np.newaxis, np.newaxis] == B)\n",
|
"C = (A[..., np.newaxis, np.newaxis] == B)\n",
|
||||||
"rows = (C.sum(axis=(1,2,3)) >= B.shape[1]).nonzero()[0]\n",
|
"rows = np.where(C.any((3,1)).all(1))[0]\n",
|
||||||
"print(rows)"
|
"print(rows)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1097,7 +1097,7 @@ A = np.random.randint(0,5,(8,3))
|
|||||||
B = np.random.randint(0,5,(2,2))
|
B = np.random.randint(0,5,(2,2))
|
||||||
|
|
||||||
C = (A[..., np.newaxis, np.newaxis] == B)
|
C = (A[..., np.newaxis, np.newaxis] == B)
|
||||||
rows = (C.sum(axis=(1,2,3)) >= B.shape[1]).nonzero()[0]
|
rows = np.where(C.any((3,1)).all(1))[0]
|
||||||
print(rows)
|
print(rows)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user