diff --git a/subjects/ai/numpy/README.md b/subjects/ai/numpy/README.md index 1a70d8035..0c427bc79 100644 --- a/subjects/ai/numpy/README.md +++ b/subjects/ai/numpy/README.md @@ -156,7 +156,7 @@ The goal of this exercise is to learn to concatenate and reshape arrays. The goal of this exercise is to learn to access values of n-dimensional arrays efficiently. 1. Create an 2-dimensional array size 9,9 of 1s. Each value has to be an `int8`. -2. Using **slicing**, output this array: +2. Using a combination of **slicing** and **broadcasting**, output this array: ```python array([[1, 1, 1, 1, 1, 1, 1, 1, 1], diff --git a/subjects/ai/numpy/audit/README.md b/subjects/ai/numpy/audit/README.md index baa4680ee..427715be2 100644 --- a/subjects/ai/numpy/audit/README.md +++ b/subjects/ai/numpy/audit/README.md @@ -186,15 +186,17 @@ https://jakevdp.github.io/PythonDataScienceHandbook/ (section: The Basics of Num [1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=int8) ``` -##### The solution of question 2 is not accepted if the values of the array have been changed one by one manually. The usage of the for loop is not allowed neither. +##### The solution of question 2 is not accepted if the values of the array have been changed one by one manually. Here is an example of a possible solution: -```console - x[1:8,1:8] = 0 - x[2:7,2:7] = 1 - x[3:6,3:6] = 0 - x[4,4] = 1 +```python +for step in range(1, 5): + array_len = 9 - step * 2 + if step % 2 == 1: + x[step:-step, step:-step] -= np.ones(array_len, dtype='int8') + else: + x[step:-step, step:-step] += np.ones(array_len, dtype='int8') ``` ---