2020-08-13 12:00:20 +02:00
|
|
|
---
|
|
|
|
id: 5e9a0a8e09c5df3cc3600ed6
|
|
|
|
challengeType: 11
|
|
|
|
videoId: 0jGfH8BPfOk
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: initialize-array-problem
|
2020-08-13 12:00:20 +02:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --question--
|
2020-08-13 12:00:20 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
## --text--
|
2020-08-13 12:00:20 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
What is another way to produce the following array?
|
2020-08-13 12:00:20 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```py
|
|
|
|
[[1. 1. 1. 1. 1.]
|
|
|
|
[1. 0. 0. 0. 1.]
|
|
|
|
[1. 0. 9. 0. 1.]
|
|
|
|
[1. 0. 0. 0. 1.]
|
|
|
|
[1. 1. 1. 1. 1.]]
|
|
|
|
```
|
2020-08-13 12:00:20 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
## --answers--
|
2020-08-13 12:00:20 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```py
|
|
|
|
output = np.ones((5, 5))
|
2020-08-13 12:00:20 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
z = np.zeros((3, 3))
|
|
|
|
z[1, 1] = 9
|
2020-08-13 12:00:20 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
output[1:-1, 1:-1] = z
|
|
|
|
```
|
2020-08-13 12:00:20 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
---
|
|
|
|
|
|
|
|
```py
|
|
|
|
output = np.ones((5, 5))
|
|
|
|
|
|
|
|
z = np.zeros((3, 3))
|
|
|
|
z[1, 1] = 9
|
|
|
|
|
|
|
|
output[1:3, 1:3] = z
|
|
|
|
```
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
```py
|
|
|
|
output = np.ones((5, 5))
|
|
|
|
|
|
|
|
z = np.zeros((3, 3))
|
|
|
|
z[1, 1] = 9
|
|
|
|
|
|
|
|
output[4:1, 4:1] = z
|
|
|
|
```
|
|
|
|
|
|
|
|
## --video-solution--
|
2020-08-13 12:00:20 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
1
|
2020-08-13 12:00:20 +02:00
|
|
|
|