From 45e1fc47b5b91fba87fd39f146d6af236a0809bb Mon Sep 17 00:00:00 2001 From: daviddoji Date: Thu, 19 Aug 2021 19:27:05 +0200 Subject: [PATCH] Alternative solution to exercise 4 --- 100_Numpy_exercises_with_hints.md | 4 ++-- 100_Numpy_exercises_with_hints_with_solutions.md | 6 +++--- 100_Numpy_exercises_with_solutions.md | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/100_Numpy_exercises_with_hints.md b/100_Numpy_exercises_with_hints.md index 5b8db89f..1457bc57 100644 --- a/100_Numpy_exercises_with_hints.md +++ b/100_Numpy_exercises_with_hints.md @@ -19,7 +19,7 @@ File automatically generated. See the documentation to update questions/answers/ #### 3. Create a null vector of size 10 (★☆☆) `hint: np.zeros` #### 4. How to find the memory size of any array (★☆☆) -`hint: size, itemsize` +`hint: size, itemsize, nbytes` #### 5. How to get the documentation of the numpy add function from the command line? (★☆☆) `hint: np.info` #### 6. Create a null vector of size 10 but the fifth value which is 1 (★☆☆) @@ -247,4 +247,4 @@ np.sqrt(-1) == np.emath.sqrt(-1) #### 99. Given an integer n and a 2D array X, select from X the rows which can be interpreted as draws from a multinomial distribution with n degrees, i.e., the rows which only contain integers and which sum to n. (★★★) `hint: np.logical_and.reduce, np.mod` #### 100. Compute bootstrapped 95% confidence intervals for the mean of a 1D array X (i.e., resample the elements of an array with replacement N times, compute the mean of each sample, and then compute percentiles over the means). (★★★) -`hint: np.percentile` \ No newline at end of file +`hint: np.percentile` diff --git a/100_Numpy_exercises_with_hints_with_solutions.md b/100_Numpy_exercises_with_hints_with_solutions.md index 5a623960..de0f2978 100644 --- a/100_Numpy_exercises_with_hints_with_solutions.md +++ b/100_Numpy_exercises_with_hints_with_solutions.md @@ -33,11 +33,11 @@ Z = np.zeros(10) print(Z) ``` #### 4. How to find the memory size of any array (★☆☆) -`hint: size, itemsize` +`hint: size, itemsize, nbytes` ```python Z = np.zeros((10,10)) -print("%d bytes" % (Z.size * Z.itemsize)) +print("%d bytes (%d bytes, using "nbytes")" % ((Z.size * Z.itemsize), Z.nbytes)) ``` #### 5. How to get the documentation of the numpy add function from the command line? (★☆☆) `hint: np.info` @@ -1205,4 +1205,4 @@ idx = np.random.randint(0, X.size, (N, X.size)) means = X[idx].mean(axis=1) confint = np.percentile(means, [2.5, 97.5]) print(confint) -``` \ No newline at end of file +``` diff --git a/100_Numpy_exercises_with_solutions.md b/100_Numpy_exercises_with_solutions.md index b332550f..7df4e6ce 100644 --- a/100_Numpy_exercises_with_solutions.md +++ b/100_Numpy_exercises_with_solutions.md @@ -37,7 +37,7 @@ print(Z) ```python Z = np.zeros((10,10)) -print("%d bytes" % (Z.size * Z.itemsize)) +print("%d bytes (%d bytes, using "nbytes")" % ((Z.size * Z.itemsize), Z.nbytes)) ``` #### 5. How to get the documentation of the numpy add function from the command line? (★☆☆) @@ -1205,4 +1205,4 @@ idx = np.random.randint(0, X.size, (N, X.size)) means = X[idx].mean(axis=1) confint = np.percentile(means, [2.5, 97.5]) print(confint) -``` \ No newline at end of file +```