Skip to content

Commit 733e2c3

Browse files
committed
Solution to How to find rows of A that contain elements of each row of B
1 parent 9e3eb1d commit 733e2c3

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

100 Numpy exercises.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,7 @@
21272127
"B = np.random.randint(0,5,(2,2))\n",
21282128
"\n",
21292129
"C = (A[..., np.newaxis, np.newaxis] == B)\n",
2130-
"rows = (C.sum(axis=(1,2,3)) >= B.shape[1]).nonzero()[0]\n",
2130+
"rows = np.where(C.any((3,1)).all(1))[0]\n",
21312131
"print(rows)"
21322132
]
21332133
},

100 Numpy exercises.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ A = np.random.randint(0,5,(8,3))
10971097
B = np.random.randint(0,5,(2,2))
10981098

10991099
C = (A[..., np.newaxis, np.newaxis] == B)
1100-
rows = (C.sum(axis=(1,2,3)) >= B.shape[1]).nonzero()[0]
1100+
rows = np.where(C.any((3,1)).all(1))[0]
11011101
print(rows)
11021102
```
11031103

0 commit comments

Comments
 (0)