Compare commits
15 Commits
9be9c8cd23
...
564a329151
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
564a329151 | ||
|
|
19dcbdd422 | ||
|
|
5c3481111f | ||
|
|
2db57d0e16 | ||
|
|
836eab7578 | ||
|
|
521b1c0c75 | ||
|
|
18a5097890 | ||
|
|
5b6d050a52 | ||
|
|
8ea76d1f91 | ||
|
|
fc72693160 | ||
|
|
301e0eb61e | ||
|
|
59a403da66 | ||
|
|
fca297a6e1 | ||
|
|
ed0a067b01 | ||
|
|
ee15dec2c7 |
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,9 @@ print(Z)
|
|||||||
```python
|
```python
|
||||||
Z = np.zeros((10,10))
|
Z = np.zeros((10,10))
|
||||||
print("%d bytes" % (Z.size * Z.itemsize))
|
print("%d bytes" % (Z.size * Z.itemsize))
|
||||||
|
|
||||||
|
# Simpler alternative
|
||||||
|
print("%d bytes" % Z.nbytes)
|
||||||
```
|
```
|
||||||
#### 5. How to get the documentation of the numpy add function from the command line? (★☆☆)
|
#### 5. How to get the documentation of the numpy add function from the command line? (★☆☆)
|
||||||
`hint: np.info`
|
`hint: np.info`
|
||||||
@@ -993,7 +996,8 @@ print(sliding_window_view(Z, window_shape=4))
|
|||||||
|
|
||||||
Z = np.random.uniform(0,1,(10,10))
|
Z = np.random.uniform(0,1,(10,10))
|
||||||
U, S, V = np.linalg.svd(Z) # Singular Value Decomposition
|
U, S, V = np.linalg.svd(Z) # Singular Value Decomposition
|
||||||
rank = np.sum(S > 1e-10)
|
threshold = len(S) * S.max() * np.finfo(S.dtype).eps
|
||||||
|
rank = np.sum(S > threshold)
|
||||||
print(rank)
|
print(rank)
|
||||||
|
|
||||||
# alternative solution:
|
# alternative solution:
|
||||||
@@ -1086,11 +1090,8 @@ k = 4
|
|||||||
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
|
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
|
||||||
S = windows[::k, ::k, ...].sum(axis=(-2, -1))
|
S = windows[::k, ::k, ...].sum(axis=(-2, -1))
|
||||||
|
|
||||||
# Author: Jeff Luo (@Jeff1999)
|
# alternative solution (by @Gattocrucco)
|
||||||
|
S = Z.reshape(4, 4, 4, 4).sum((1, 3))
|
||||||
Z = np.ones((16, 16))
|
|
||||||
k = 4
|
|
||||||
print(sliding_window_view(Z, window_shape=(k, k))[::k, ::k].sum(axis=(-2, -1)))
|
|
||||||
```
|
```
|
||||||
#### 88. How to implement the Game of Life using numpy arrays? (★★★)
|
#### 88. How to implement the Game of Life using numpy arrays? (★★★)
|
||||||
`No hints provided...`
|
`No hints provided...`
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ print(Z)
|
|||||||
```python
|
```python
|
||||||
Z = np.zeros((10,10))
|
Z = np.zeros((10,10))
|
||||||
print("%d bytes" % (Z.size * Z.itemsize))
|
print("%d bytes" % (Z.size * Z.itemsize))
|
||||||
|
|
||||||
|
# Simpler alternative
|
||||||
|
print("%d bytes" % Z.nbytes)
|
||||||
```
|
```
|
||||||
#### 5. How to get the documentation of the numpy add function from the command line? (★☆☆)
|
#### 5. How to get the documentation of the numpy add function from the command line? (★☆☆)
|
||||||
|
|
||||||
@@ -993,7 +996,8 @@ print(sliding_window_view(Z, window_shape=4))
|
|||||||
|
|
||||||
Z = np.random.uniform(0,1,(10,10))
|
Z = np.random.uniform(0,1,(10,10))
|
||||||
U, S, V = np.linalg.svd(Z) # Singular Value Decomposition
|
U, S, V = np.linalg.svd(Z) # Singular Value Decomposition
|
||||||
rank = np.sum(S > 1e-10)
|
threshold = len(S) * S.max() * np.finfo(S.dtype).eps
|
||||||
|
rank = np.sum(S > threshold)
|
||||||
print(rank)
|
print(rank)
|
||||||
|
|
||||||
# alternative solution:
|
# alternative solution:
|
||||||
@@ -1086,11 +1090,8 @@ k = 4
|
|||||||
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
|
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
|
||||||
S = windows[::k, ::k, ...].sum(axis=(-2, -1))
|
S = windows[::k, ::k, ...].sum(axis=(-2, -1))
|
||||||
|
|
||||||
# Author: Jeff Luo (@Jeff1999)
|
# alternative solution (by @Gattocrucco)
|
||||||
|
S = Z.reshape(4, 4, 4, 4).sum((1, 3))
|
||||||
Z = np.ones((16, 16))
|
|
||||||
k = 4
|
|
||||||
print(sliding_window_view(Z, window_shape=(k, k))[::k, ::k].sum(axis=(-2, -1)))
|
|
||||||
```
|
```
|
||||||
#### 88. How to implement the Game of Life using numpy arrays? (★★★)
|
#### 88. How to implement the Game of Life using numpy arrays? (★★★)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "738eba3f",
|
"id": "af9e3994",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# 100 numpy exercises\n",
|
"# 100 numpy exercises\n",
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "f65f901e",
|
"id": "76e99d49",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"File automatically generated. See the documentation to update questions/answers/hints programmatically."
|
"File automatically generated. See the documentation to update questions/answers/hints programmatically."
|
||||||
@@ -26,17 +26,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "15045647",
|
"id": "8a54b21a",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Run the `initialize.py` module, then call a random question with `pick()` an hint towards its solution with\n",
|
"Run the `initialise.py` module, then call a random question with `pick()` an hint towards its solution with\n",
|
||||||
"`hint(n)` and the answer with `answer(n)`, where n is the number of the picked question."
|
"`hint(n)` and the answer with `answer(n)`, where n is the number of the picked question."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "0d23aa5b",
|
"id": "670bb646",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "4a6a613b",
|
"id": "4ff49967",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ hint: size, itemsize
|
|||||||
Z = np.zeros((10,10))
|
Z = np.zeros((10,10))
|
||||||
print("%d bytes" % (Z.size * Z.itemsize))
|
print("%d bytes" % (Z.size * Z.itemsize))
|
||||||
|
|
||||||
|
# Simpler alternative
|
||||||
|
print("%d bytes" % Z.nbytes)
|
||||||
|
|
||||||
< q5
|
< q5
|
||||||
How to get the documentation of the numpy add function from the command line? (★☆☆)
|
How to get the documentation of the numpy add function from the command line? (★☆☆)
|
||||||
|
|
||||||
@@ -1225,7 +1228,8 @@ hint: np.linalg.svd, np.linalg.matrix_rank
|
|||||||
|
|
||||||
Z = np.random.uniform(0,1,(10,10))
|
Z = np.random.uniform(0,1,(10,10))
|
||||||
U, S, V = np.linalg.svd(Z) # Singular Value Decomposition
|
U, S, V = np.linalg.svd(Z) # Singular Value Decomposition
|
||||||
rank = np.sum(S > 1e-10)
|
threshold = len(S) * S.max() * np.finfo(S.dtype).eps
|
||||||
|
rank = np.sum(S > threshold)
|
||||||
print(rank)
|
print(rank)
|
||||||
|
|
||||||
# alternative solution:
|
# alternative solution:
|
||||||
@@ -1333,11 +1337,8 @@ k = 4
|
|||||||
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
|
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
|
||||||
S = windows[::k, ::k, ...].sum(axis=(-2, -1))
|
S = windows[::k, ::k, ...].sum(axis=(-2, -1))
|
||||||
|
|
||||||
# Author: Jeff Luo (@Jeff1999)
|
# alternative solution (by @Gattocrucco)
|
||||||
|
S = Z.reshape(4, 4, 4, 4).sum((1, 3))
|
||||||
Z = np.ones((16, 16))
|
|
||||||
k = 4
|
|
||||||
print(sliding_window_view(Z, window_shape=(k, k))[::k, ::k].sum(axis=(-2, -1)))
|
|
||||||
|
|
||||||
< q88
|
< q88
|
||||||
How to implement the Game of Life using numpy arrays? (★★★)
|
How to implement the Game of Life using numpy arrays? (★★★)
|
||||||
|
|||||||
Reference in New Issue
Block a user