Merge pull request #152 from FirefoxMetzger/additional_solution
alternative solution for no. 87
This commit is contained in:
commit
c3497d3bc3
@ -995,6 +995,15 @@ k = 4
|
||||
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)
|
||||
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? (★★★)
|
||||
`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),
|
||||
np.arange(0, Z.shape[1], k), axis=1)
|
||||
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? (★★★)
|
||||
|
||||
|
@ -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)
|
||||
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
|
||||
How to implement the Game of Life using numpy arrays? (★★★)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user