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