Browse Source

feat(numpy): update exercise 6 subject and audit

- Make exercise relevant to the topic of broadcasting
pull/2304/head
nprimo 10 months ago committed by Niccolò Primo
parent
commit
30b2d02f50
  1. 2
      subjects/ai/numpy/README.md
  2. 14
      subjects/ai/numpy/audit/README.md

2
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],

14
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')
```
---

Loading…
Cancel
Save