alternative solution for no. 87
This commit is contained in:
parent
0087eccf20
commit
72fc6399b2
@ -995,6 +995,15 @@ k = 4
|
|||||||
S = np.add.reduceat(np.add.reduceat(Z, np.arange(0, Z.shape[0], k), axis=0),
|
S = np.add.reduceat(np.add.reduceat(Z, np.arange(0, Z.shape[0], k), axis=0),
|
||||||
np.arange(0, Z.shape[1], k), axis=1)
|
np.arange(0, Z.shape[1], k), axis=1)
|
||||||
print(S)
|
print(S)
|
||||||
|
|
||||||
|
# alternative solution:
|
||||||
|
# Author: Sebastian Wallkötter (@FirefoxMetzger)
|
||||||
|
|
||||||
|
Z = np.ones((16,16))
|
||||||
|
k = 4
|
||||||
|
|
||||||
|
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
|
||||||
|
S = windows[::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...`
|
||||||
|
@ -995,6 +995,15 @@ k = 4
|
|||||||
S = np.add.reduceat(np.add.reduceat(Z, np.arange(0, Z.shape[0], k), axis=0),
|
S = np.add.reduceat(np.add.reduceat(Z, np.arange(0, Z.shape[0], k), axis=0),
|
||||||
np.arange(0, Z.shape[1], k), axis=1)
|
np.arange(0, Z.shape[1], k), axis=1)
|
||||||
print(S)
|
print(S)
|
||||||
|
|
||||||
|
# alternative solution:
|
||||||
|
# Author: Sebastian Wallkötter (@FirefoxMetzger)
|
||||||
|
|
||||||
|
Z = np.ones((16,16))
|
||||||
|
k = 4
|
||||||
|
|
||||||
|
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
|
||||||
|
S = windows[::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? (★★★)
|
||||||
|
|
||||||
|
@ -1243,6 +1243,15 @@ S = np.add.reduceat(np.add.reduceat(Z, np.arange(0, Z.shape[0], k), axis=0),
|
|||||||
np.arange(0, Z.shape[1], k), axis=1)
|
np.arange(0, Z.shape[1], k), axis=1)
|
||||||
print(S)
|
print(S)
|
||||||
|
|
||||||
|
# alternative solution:
|
||||||
|
# Author: Sebastian Wallkötter (@FirefoxMetzger)
|
||||||
|
|
||||||
|
Z = np.ones((16,16))
|
||||||
|
k = 4
|
||||||
|
|
||||||
|
windows = np.lib.stride_tricks.sliding_window_view(Z, (k, k))
|
||||||
|
S = windows[::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? (★★★)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user