Skip to content

Commit 946647c

Browse files
committed
Adding an alternative solution to the 'extract rows with unequal values' exercise
1 parent 37e7fe2 commit 946647c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

100 Numpy exercises.ipynb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,12 @@
21492149
"# Author: Robert Kern\n",
21502150
"\n",
21512151
"Z = np.random.randint(0,5,(10,3))\n",
2152+
"print(Z)\n",
2153+
"# solution for arrays of all dtypes (including string arrays and record arrays)\n",
2154+
"E = np.all(Z[:,1:] == Z[:,:-1], axis=1)\n",
2155+
"U = Z[~E]\n",
2156+
"print(U)\n",
2157+
"# soluiton for numerical arrays only, will work for any number of columns in Z\n",
21522158
"U = Z[Z.max(axis=1) != Z.min(axis=1),:]\n",
21532159
"print(U)"
21542160
]

100 Numpy exercises.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,12 @@ print(rows)
11081108
# Author: Robert Kern
11091109

11101110
Z = np.random.randint(0,5,(10,3))
1111+
print(Z)
1112+
# solution for arrays of all dtypes (including string arrays and record arrays)
1113+
E = np.all(Z[:,1:] == Z[:,:-1], axis=1)
1114+
U = Z[~E]
1115+
print(U)
1116+
# soluiton for numerical arrays only, will work for any number of columns in Z
11111117
U = Z[Z.max(axis=1) != Z.min(axis=1),:]
11121118
print(U)
11131119
```

0 commit comments

Comments
 (0)