From b2a4a9e819eb51d6cfde7c3478667584cdb77a1f Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 3 Jun 2020 14:58:44 -0700 Subject: [PATCH] Q16 Alternate Solution --- 100_Numpy_exercises_with_hints_with_solutions.md | 5 +++++ 100_Numpy_exercises_with_solutions.md | 5 +++++ source/exercises100.ktx | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/100_Numpy_exercises_with_hints_with_solutions.md b/100_Numpy_exercises_with_hints_with_solutions.md index d047d55..01a01a1 100644 --- a/100_Numpy_exercises_with_hints_with_solutions.md +++ b/100_Numpy_exercises_with_hints_with_solutions.md @@ -127,6 +127,11 @@ print(Z) Z = np.ones((5,5)) Z = np.pad(Z, pad_width=1, mode='constant', constant_values=0) print(Z) + +# Using fancy indexing +Z[:, [0, -1]] = 0 +Z[[0, -1], :] = 0 +print(Z) ``` #### 17. What is the result of the following expression? (★☆☆) ```python diff --git a/100_Numpy_exercises_with_solutions.md b/100_Numpy_exercises_with_solutions.md index 61720d0..45fcc7c 100644 --- a/100_Numpy_exercises_with_solutions.md +++ b/100_Numpy_exercises_with_solutions.md @@ -127,6 +127,11 @@ print(Z) Z = np.ones((5,5)) Z = np.pad(Z, pad_width=1, mode='constant', constant_values=0) print(Z) + +# Using fancy indexing +Z[:, [0, -1]] = 0 +Z[[0, -1], :] = 0 +print(Z) ``` #### 17. What is the result of the following expression? (★☆☆) ```python diff --git a/source/exercises100.ktx b/source/exercises100.ktx index 4d48b02..1fb8729 100644 --- a/source/exercises100.ktx +++ b/source/exercises100.ktx @@ -162,6 +162,11 @@ Z = np.ones((5,5)) Z = np.pad(Z, pad_width=1, mode='constant', constant_values=0) print(Z) +# Using fancy indexing +Z[:, [0, -1]] = 0 +Z[[0, -1], :] = 0 +print(Z) + < q17 What is the result of the following expression? (★☆☆) ```python