diff --git a/100_Numpy_exercises.ipynb b/100_Numpy_exercises.ipynb index ae49130..d5b1152 100644 --- a/100_Numpy_exercises.ipynb +++ b/100_Numpy_exercises.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "c742d9cc", + "id": "bf79c78b", "metadata": {}, "source": [ "# 100 numpy exercises\n", @@ -18,7 +18,7 @@ }, { "cell_type": "markdown", - "id": "4292e21c", + "id": "8536e059", "metadata": {}, "source": [ "File automatically generated. See the documentation to update questions/answers/hints programmatically." @@ -26,7 +26,7 @@ }, { "cell_type": "markdown", - "id": "e1eba8a7", + "id": "e16ac60b", "metadata": {}, "source": [ "Run the `initialize.py` module, then for each question you can query the\n", @@ -36,7 +36,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1ca6f730", + "id": "a8453483", "metadata": {}, "outputs": [], "source": [ @@ -45,7 +45,7 @@ }, { "cell_type": "markdown", - "id": "c6ed9243", + "id": "017db353", "metadata": {}, "source": [ "#### 1. Import the numpy package under the name `np` (★☆☆)" @@ -54,14 +54,14 @@ { "cell_type": "code", "execution_count": null, - "id": "4dc18925", + "id": "68182a76", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "b4882d94", + "id": "46950f4f", "metadata": {}, "source": [ "#### 2. Print the numpy version and the configuration (★☆☆)" @@ -70,14 +70,14 @@ { "cell_type": "code", "execution_count": null, - "id": "9a41fb2b", + "id": "2a9f5838", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "084258bf", + "id": "e3c20b3d", "metadata": {}, "source": [ "#### 3. Create a null vector of size 10 (★☆☆)" @@ -86,14 +86,14 @@ { "cell_type": "code", "execution_count": null, - "id": "660c6b91", + "id": "8a758bcf", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "0b7ea863", + "id": "b15a879f", "metadata": {}, "source": [ "#### 4. How to find the memory size of any array (★☆☆)" @@ -102,14 +102,14 @@ { "cell_type": "code", "execution_count": null, - "id": "ac12eeb3", + "id": "1cc3cbc5", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "399ac53c", + "id": "0a708990", "metadata": {}, "source": [ "#### 5. How to get the documentation of the numpy add function from the command line? (★☆☆)" @@ -118,14 +118,14 @@ { "cell_type": "code", "execution_count": null, - "id": "8706e03d", + "id": "477e01f4", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "94fb58be", + "id": "0b16cd77", "metadata": {}, "source": [ "#### 6. Create a null vector of size 10 but the fifth value which is 1 (★☆☆)" @@ -134,14 +134,14 @@ { "cell_type": "code", "execution_count": null, - "id": "618f340f", + "id": "4d9b5975", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "d577e66c", + "id": "782d4c77", "metadata": {}, "source": [ "#### 7. Create a vector with values ranging from 10 to 49 (★☆☆)" @@ -150,14 +150,14 @@ { "cell_type": "code", "execution_count": null, - "id": "091a60f4", + "id": "5dbe1a08", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "bc9c60e2", + "id": "48d48f01", "metadata": {}, "source": [ "#### 8. Reverse a vector (first element becomes last) (★☆☆)" @@ -166,14 +166,14 @@ { "cell_type": "code", "execution_count": null, - "id": "23978628", + "id": "3ed233e7", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "7454fb7b", + "id": "4fa39382", "metadata": {}, "source": [ "#### 9. Create a 3x3 matrix with values ranging from 0 to 8 (★☆☆)" @@ -182,14 +182,14 @@ { "cell_type": "code", "execution_count": null, - "id": "28f9a38f", + "id": "c97757ec", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "caf21358", + "id": "da64551a", "metadata": {}, "source": [ "#### 10. Find indices of non-zero elements from [1,2,0,0,4,0] (★☆☆)" @@ -198,14 +198,14 @@ { "cell_type": "code", "execution_count": null, - "id": "d390f4e1", + "id": "327f7adb", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "1dd829ac", + "id": "f89d9c9e", "metadata": {}, "source": [ "#### 11. Create a 3x3 identity matrix (★☆☆)" @@ -214,14 +214,14 @@ { "cell_type": "code", "execution_count": null, - "id": "1dde894f", + "id": "ba625832", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "322aa74e", + "id": "7e44c6fa", "metadata": {}, "source": [ "#### 12. Create a 3x3x3 array with random values (★☆☆)" @@ -230,14 +230,14 @@ { "cell_type": "code", "execution_count": null, - "id": "1f5c8d38", + "id": "1cb3dddf", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "82e8c932", + "id": "13c5928c", "metadata": {}, "source": [ "#### 13. Create a 10x10 array with random values and find the minimum and maximum values (★☆☆)" @@ -246,14 +246,14 @@ { "cell_type": "code", "execution_count": null, - "id": "85c6a59d", + "id": "911c9b93", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "c78b3d5e", + "id": "3fa2e461", "metadata": {}, "source": [ "#### 14. Create a random vector of size 30 and find the mean value (★☆☆)" @@ -262,14 +262,14 @@ { "cell_type": "code", "execution_count": null, - "id": "37149237", + "id": "323eb38a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "c07320af", + "id": "73f7a549", "metadata": {}, "source": [ "#### 15. Create a 2d array with 1 on the border and 0 inside (★☆☆)" @@ -278,14 +278,14 @@ { "cell_type": "code", "execution_count": null, - "id": "19897ca9", + "id": "e3a6807d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "c6d094c4", + "id": "6d0c506f", "metadata": {}, "source": [ "#### 16. How to add a border (filled with 0's) around an existing array? (★☆☆)" @@ -294,14 +294,14 @@ { "cell_type": "code", "execution_count": null, - "id": "9c05295e", + "id": "32ffee7b", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "6e00ebde", + "id": "d6ad1a9f", "metadata": {}, "source": [ "#### 17. What is the result of the following expression? (★☆☆)\n", @@ -318,14 +318,14 @@ { "cell_type": "code", "execution_count": null, - "id": "5015d2a2", + "id": "ee7ff0f3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "ffee7be0", + "id": "e3a7ba7f", "metadata": {}, "source": [ "#### 18. Create a 5x5 matrix with values 1,2,3,4 just below the diagonal (★☆☆)" @@ -334,14 +334,14 @@ { "cell_type": "code", "execution_count": null, - "id": "2db510c1", + "id": "01d8e257", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "0c687bd7", + "id": "6d17ab5d", "metadata": {}, "source": [ "#### 19. Create a 8x8 matrix and fill it with a checkerboard pattern (★☆☆)" @@ -350,30 +350,30 @@ { "cell_type": "code", "execution_count": null, - "id": "c7a51f78", + "id": "841373cd", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "46c55b45", + "id": "8837119b", "metadata": {}, "source": [ - "#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element?" + "#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? (★☆☆)" ] }, { "cell_type": "code", "execution_count": null, - "id": "d95d1406", + "id": "2c0d16f1", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "4898dddb", + "id": "ec788c9f", "metadata": {}, "source": [ "#### 21. Create a checkerboard 8x8 matrix using the tile function (★☆☆)" @@ -382,14 +382,14 @@ { "cell_type": "code", "execution_count": null, - "id": "de7dc9d8", + "id": "0a4f919f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "ef2963f0", + "id": "391791e0", "metadata": {}, "source": [ "#### 22. Normalize a 5x5 random matrix (★☆☆)" @@ -398,14 +398,14 @@ { "cell_type": "code", "execution_count": null, - "id": "f92f76ce", + "id": "f6533d39", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "09390c44", + "id": "1e74d39e", "metadata": {}, "source": [ "#### 23. Create a custom dtype that describes a color as four unsigned bytes (RGBA) (★☆☆)" @@ -414,14 +414,14 @@ { "cell_type": "code", "execution_count": null, - "id": "86bea398", + "id": "3f639d33", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "e8ff25fc", + "id": "78250c14", "metadata": {}, "source": [ "#### 24. Multiply a 5x3 matrix by a 3x2 matrix (real matrix product) (★☆☆)" @@ -430,14 +430,14 @@ { "cell_type": "code", "execution_count": null, - "id": "bcb2fa2e", + "id": "9fe729cb", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "ce43c805", + "id": "51898680", "metadata": {}, "source": [ "#### 25. Given a 1D array, negate all elements which are between 3 and 8, in place. (★☆☆)" @@ -446,14 +446,14 @@ { "cell_type": "code", "execution_count": null, - "id": "2b915f12", + "id": "51c90f2d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "20696fea", + "id": "89e78048", "metadata": {}, "source": [ "#### 26. What is the output of the following script? (★☆☆)\n", @@ -469,14 +469,14 @@ { "cell_type": "code", "execution_count": null, - "id": "89d43108", + "id": "b62e9d1c", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "9f3e3396", + "id": "ebd10810", "metadata": {}, "source": [ "#### 27. Consider an integer vector Z, which of these expressions are legal? (★☆☆)\n", @@ -493,17 +493,17 @@ { "cell_type": "code", "execution_count": null, - "id": "fa6a4ad1", + "id": "6ada209f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "99a826bb", + "id": "c0e940f8", "metadata": {}, "source": [ - "#### 28. What are the result of the following expressions?\n", + "#### 28. What are the result of the following expressions? (★☆☆)\n", "```python\n", "np.array(0) / np.array(0)\n", "np.array(0) // np.array(0)\n", @@ -514,14 +514,14 @@ { "cell_type": "code", "execution_count": null, - "id": "f5178b8b", + "id": "820dc7a5", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "04270e58", + "id": "22713c3f", "metadata": {}, "source": [ "#### 29. How to round away from zero a float array ? (★☆☆)" @@ -530,14 +530,14 @@ { "cell_type": "code", "execution_count": null, - "id": "7dcb8271", + "id": "a3e05c29", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "186af0bd", + "id": "f1ae2c2d", "metadata": {}, "source": [ "#### 30. How to find common values between two arrays? (★☆☆)" @@ -546,14 +546,14 @@ { "cell_type": "code", "execution_count": null, - "id": "751ce3d6", + "id": "6801c73d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "8dc246e6", + "id": "34a7bdee", "metadata": {}, "source": [ "#### 31. How to ignore all numpy warnings (not recommended)? (★☆☆)" @@ -562,14 +562,14 @@ { "cell_type": "code", "execution_count": null, - "id": "882d5831", + "id": "befc60d1", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "46286b98", + "id": "37bc0973", "metadata": {}, "source": [ "#### 32. Is the following expressions true? (★☆☆)\n", @@ -581,14 +581,14 @@ { "cell_type": "code", "execution_count": null, - "id": "35b2ee6a", + "id": "c70cbabe", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "c19f893b", + "id": "129c342d", "metadata": {}, "source": [ "#### 33. How to get the dates of yesterday, today and tomorrow? (★☆☆)" @@ -597,14 +597,14 @@ { "cell_type": "code", "execution_count": null, - "id": "39f552e8", + "id": "8ba1badb", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "7507fb36", + "id": "42f8b2f9", "metadata": {}, "source": [ "#### 34. How to get all the dates corresponding to the month of July 2016? (★★☆)" @@ -613,14 +613,14 @@ { "cell_type": "code", "execution_count": null, - "id": "23c538eb", + "id": "eb8ebe45", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "d62fba94", + "id": "252c43e2", "metadata": {}, "source": [ "#### 35. How to compute ((A+B)*(-A/2)) in place (without copy)? (★★☆)" @@ -629,14 +629,14 @@ { "cell_type": "code", "execution_count": null, - "id": "b517ffa9", + "id": "f06ff615", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "0593c304", + "id": "486df8ea", "metadata": {}, "source": [ "#### 36. Extract the integer part of a random array of positive numbers using 4 different methods (★★☆)" @@ -645,14 +645,14 @@ { "cell_type": "code", "execution_count": null, - "id": "9c7ad92e", + "id": "34b4fa08", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "e90b042b", + "id": "649e89f9", "metadata": {}, "source": [ "#### 37. Create a 5x5 matrix with row values ranging from 0 to 4 (★★☆)" @@ -661,14 +661,14 @@ { "cell_type": "code", "execution_count": null, - "id": "7892b4b0", + "id": "663cc611", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "a2d7df8e", + "id": "3421e17f", "metadata": {}, "source": [ "#### 38. Consider a generator function that generates 10 integers and use it to build an array (★☆☆)" @@ -677,14 +677,14 @@ { "cell_type": "code", "execution_count": null, - "id": "5f323469", + "id": "7336b8e4", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "064c68c0", + "id": "483dd554", "metadata": {}, "source": [ "#### 39. Create a vector of size 10 with values ranging from 0 to 1, both excluded (★★☆)" @@ -693,14 +693,14 @@ { "cell_type": "code", "execution_count": null, - "id": "a179d69e", + "id": "c89b93e7", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "5682b5b3", + "id": "2d07be1c", "metadata": {}, "source": [ "#### 40. Create a random vector of size 10 and sort it (★★☆)" @@ -709,14 +709,14 @@ { "cell_type": "code", "execution_count": null, - "id": "f5e5b511", + "id": "4f7cb3ad", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "c8831686", + "id": "6415f02e", "metadata": {}, "source": [ "#### 41. How to sum a small array faster than np.sum? (★★☆)" @@ -725,14 +725,14 @@ { "cell_type": "code", "execution_count": null, - "id": "31c6ec4d", + "id": "bb0dd942", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "c39eed1e", + "id": "fe043549", "metadata": {}, "source": [ "#### 42. Consider two random array A and B, check if they are equal (★★☆)" @@ -741,14 +741,14 @@ { "cell_type": "code", "execution_count": null, - "id": "c4bf0ba3", + "id": "3326a686", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "ffafa4aa", + "id": "cc08f71c", "metadata": {}, "source": [ "#### 43. Make an array immutable (read-only) (★★☆)" @@ -757,14 +757,14 @@ { "cell_type": "code", "execution_count": null, - "id": "c237c0d2", + "id": "d5cc9dbe", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "86886e5e", + "id": "2002cb03", "metadata": {}, "source": [ "#### 44. Consider a random 10x2 matrix representing cartesian coordinates, convert them to polar coordinates (★★☆)" @@ -773,14 +773,14 @@ { "cell_type": "code", "execution_count": null, - "id": "5146f04c", + "id": "58be72bc", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "50740a46", + "id": "b7109c9f", "metadata": {}, "source": [ "#### 45. Create random vector of size 10 and replace the maximum value by 0 (★★☆)" @@ -789,14 +789,14 @@ { "cell_type": "code", "execution_count": null, - "id": "2c11ffdd", + "id": "f79e79a7", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "5979e3ee", + "id": "7d3131b9", "metadata": {}, "source": [ "#### 46. Create a structured array with `x` and `y` coordinates covering the [0,1]x[0,1] area (★★☆)" @@ -805,30 +805,30 @@ { "cell_type": "code", "execution_count": null, - "id": "0747c0d6", + "id": "4f471afe", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "cd53abc3", + "id": "7c8c1fc5", "metadata": {}, "source": [ - "#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj))" + "#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) (★★☆)" ] }, { "cell_type": "code", "execution_count": null, - "id": "2d14d9b7", + "id": "8fac7d28", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "37875f0d", + "id": "5795b4bd", "metadata": {}, "source": [ "#### 48. Print the minimum and maximum representable value for each numpy scalar type (★★☆)" @@ -837,14 +837,14 @@ { "cell_type": "code", "execution_count": null, - "id": "1578e3fa", + "id": "b721f7ca", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "aa4ce1fd", + "id": "fb24674c", "metadata": {}, "source": [ "#### 49. How to print all the values of an array? (★★☆)" @@ -853,14 +853,14 @@ { "cell_type": "code", "execution_count": null, - "id": "4f1e9847", + "id": "c81f1456", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "ae637202", + "id": "e6e1ae2f", "metadata": {}, "source": [ "#### 50. How to find the closest value (to a given scalar) in a vector? (★★☆)" @@ -869,14 +869,14 @@ { "cell_type": "code", "execution_count": null, - "id": "c4546e5c", + "id": "73dd91cc", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "93157464", + "id": "c01f0ecf", "metadata": {}, "source": [ "#### 51. Create a structured array representing a position (x,y) and a color (r,g,b) (★★☆)" @@ -885,14 +885,14 @@ { "cell_type": "code", "execution_count": null, - "id": "69c4b979", + "id": "fb8017ca", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "07ebafa2", + "id": "3b64a18b", "metadata": {}, "source": [ "#### 52. Consider a random vector with shape (100,2) representing coordinates, find point by point distances (★★☆)" @@ -901,14 +901,14 @@ { "cell_type": "code", "execution_count": null, - "id": "2db3c3e5", + "id": "4b482822", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "fb93d503", + "id": "48413134", "metadata": {}, "source": [ "#### 53. How to convert a float (32 bits) array into an integer (32 bits) in place?" @@ -917,14 +917,14 @@ { "cell_type": "code", "execution_count": null, - "id": "67231bf2", + "id": "5db64b6d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "9c0ce40b", + "id": "0a532633", "metadata": {}, "source": [ "#### 54. How to read the following file? (★★☆)\n", @@ -938,14 +938,14 @@ { "cell_type": "code", "execution_count": null, - "id": "aecef043", + "id": "8af4f753", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "bdfe9e5d", + "id": "f98713a6", "metadata": {}, "source": [ "#### 55. What is the equivalent of enumerate for numpy arrays? (★★☆)" @@ -954,14 +954,14 @@ { "cell_type": "code", "execution_count": null, - "id": "bcc193c9", + "id": "64795f84", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "fa2e5fc9", + "id": "1abc7cc8", "metadata": {}, "source": [ "#### 56. Generate a generic 2D Gaussian-like array (★★☆)" @@ -970,14 +970,14 @@ { "cell_type": "code", "execution_count": null, - "id": "7b94a92a", + "id": "42e3a5bc", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "465a1ea4", + "id": "0cf413ee", "metadata": {}, "source": [ "#### 57. How to randomly place p elements in a 2D array? (★★☆)" @@ -986,14 +986,14 @@ { "cell_type": "code", "execution_count": null, - "id": "c2d1d13f", + "id": "dfc57e06", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "d75998b5", + "id": "215b6acc", "metadata": {}, "source": [ "#### 58. Subtract the mean of each row of a matrix (★★☆)" @@ -1002,14 +1002,14 @@ { "cell_type": "code", "execution_count": null, - "id": "44c2043a", + "id": "dd1adef4", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "4f2e8b7a", + "id": "c0cf37e0", "metadata": {}, "source": [ "#### 59. How to sort an array by the nth column? (★★☆)" @@ -1018,14 +1018,14 @@ { "cell_type": "code", "execution_count": null, - "id": "d0b80ded", + "id": "9336ca5f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "be56980d", + "id": "c17fb213", "metadata": {}, "source": [ "#### 60. How to tell if a given 2D array has null columns? (★★☆)" @@ -1034,14 +1034,14 @@ { "cell_type": "code", "execution_count": null, - "id": "6dc4eaf6", + "id": "7fdda78d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "92e0b60c", + "id": "8aaab886", "metadata": {}, "source": [ "#### 61. Find the nearest value from a given value in an array (★★☆)" @@ -1050,14 +1050,14 @@ { "cell_type": "code", "execution_count": null, - "id": "0b37b462", + "id": "973f8079", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "476bb933", + "id": "66a04e2e", "metadata": {}, "source": [ "#### 62. Considering two arrays with shape (1,3) and (3,1), how to compute their sum using an iterator? (★★☆)" @@ -1066,14 +1066,14 @@ { "cell_type": "code", "execution_count": null, - "id": "33c8566d", + "id": "4b356632", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "64aea808", + "id": "f4427f7f", "metadata": {}, "source": [ "#### 63. Create an array class that has a name attribute (★★☆)" @@ -1082,14 +1082,14 @@ { "cell_type": "code", "execution_count": null, - "id": "db81ac8b", + "id": "fe253212", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "fb0a4de3", + "id": "58be9dd4", "metadata": {}, "source": [ "#### 64. Consider a given vector, how to add 1 to each element indexed by a second vector (be careful with repeated indices)? (★★★)" @@ -1098,14 +1098,14 @@ { "cell_type": "code", "execution_count": null, - "id": "4726a17d", + "id": "5c8bae42", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "ae1a4b8d", + "id": "7348abd0", "metadata": {}, "source": [ "#### 65. How to accumulate elements of a vector (X) to an array (F) based on an index list (I)? (★★★)" @@ -1114,14 +1114,14 @@ { "cell_type": "code", "execution_count": null, - "id": "2d0f1ee4", + "id": "b3e33a5a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "a5127520", + "id": "538e651c", "metadata": {}, "source": [ "#### 66. Considering a (w,h,3) image of (dtype=ubyte), compute the number of unique colors (★★☆)" @@ -1130,14 +1130,14 @@ { "cell_type": "code", "execution_count": null, - "id": "546bc0a2", + "id": "57f2f02f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "1eaa1407", + "id": "33c986d9", "metadata": {}, "source": [ "#### 67. Considering a four dimensions array, how to get sum over the last two axis at once? (★★★)" @@ -1146,14 +1146,14 @@ { "cell_type": "code", "execution_count": null, - "id": "7823c50c", + "id": "a99a50e2", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "18cd6a16", + "id": "00eb27c4", "metadata": {}, "source": [ "#### 68. Considering a one-dimensional vector D, how to compute means of subsets of D using a vector S of same size describing subset indices? (★★★)" @@ -1162,14 +1162,14 @@ { "cell_type": "code", "execution_count": null, - "id": "2185257f", + "id": "d48c5210", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "fb2b3f5d", + "id": "928a1a15", "metadata": {}, "source": [ "#### 69. How to get the diagonal of a dot product? (★★★)" @@ -1178,14 +1178,14 @@ { "cell_type": "code", "execution_count": null, - "id": "8ada08d1", + "id": "ef2c9ddd", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "3bb7807e", + "id": "5143f7f3", "metadata": {}, "source": [ "#### 70. Consider the vector [1, 2, 3, 4, 5], how to build a new vector with 3 consecutive zeros interleaved between each value? (★★★)" @@ -1194,14 +1194,14 @@ { "cell_type": "code", "execution_count": null, - "id": "c173afdb", + "id": "1d99a1c1", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "40e4d74e", + "id": "f62551d8", "metadata": {}, "source": [ "#### 71. Consider an array of dimension (5,5,3), how to mulitply it by an array with dimensions (5,5)? (★★★)" @@ -1210,14 +1210,14 @@ { "cell_type": "code", "execution_count": null, - "id": "32d15813", + "id": "9ab241b7", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "9ee9c5cc", + "id": "6896e326", "metadata": {}, "source": [ "#### 72. How to swap two rows of an array? (★★★)" @@ -1226,14 +1226,14 @@ { "cell_type": "code", "execution_count": null, - "id": "8499665c", + "id": "9e8fcba9", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "2a16d4e2", + "id": "aeaf4a7b", "metadata": {}, "source": [ "#### 73. Consider a set of 10 triplets describing 10 triangles (with shared vertices), find the set of unique line segments composing all the triangles (★★★)" @@ -1242,14 +1242,14 @@ { "cell_type": "code", "execution_count": null, - "id": "4f2c6e17", + "id": "39ef4234", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "75bbcb12", + "id": "3d11451b", "metadata": {}, "source": [ "#### 74. Given a sorted array C that corresponds to a bincount, how to produce an array A such that np.bincount(A) == C? (★★★)" @@ -1258,14 +1258,14 @@ { "cell_type": "code", "execution_count": null, - "id": "46ebf898", + "id": "a5563362", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "605b5b91", + "id": "a0a45995", "metadata": {}, "source": [ "#### 75. How to compute averages using a sliding window over an array? (★★★)" @@ -1274,14 +1274,14 @@ { "cell_type": "code", "execution_count": null, - "id": "b6f28d8a", + "id": "116243d5", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "0a83c91b", + "id": "7808578f", "metadata": {}, "source": [ "#### 76. Consider a one-dimensional array Z, build a two-dimensional array whose first row is (Z[0],Z[1],Z[2]) and each subsequent row is shifted by 1 (last row should be (Z[-3],Z[-2],Z[-1]) (★★★)" @@ -1290,14 +1290,14 @@ { "cell_type": "code", "execution_count": null, - "id": "78b4cfb4", + "id": "6b23ba6e", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "4be00d5e", + "id": "8e83df46", "metadata": {}, "source": [ "#### 77. How to negate a boolean, or to change the sign of a float inplace? (★★★)" @@ -1306,14 +1306,14 @@ { "cell_type": "code", "execution_count": null, - "id": "5ba94110", + "id": "f73127b7", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "23ff5523", + "id": "e67ff31c", "metadata": {}, "source": [ "#### 78. Consider 2 sets of points P0,P1 describing lines (2d) and a point p, how to compute distance from p to each line i (P0[i],P1[i])? (★★★)" @@ -1322,14 +1322,14 @@ { "cell_type": "code", "execution_count": null, - "id": "4621c4e1", + "id": "89d75b76", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "bbba6526", + "id": "ad8821b1", "metadata": {}, "source": [ "#### 79. Consider 2 sets of points P0,P1 describing lines (2d) and a set of points P, how to compute distance from each point j (P[j]) to each line i (P0[i],P1[i])? (★★★)" @@ -1338,14 +1338,14 @@ { "cell_type": "code", "execution_count": null, - "id": "a38de46e", + "id": "775feca0", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "b70a0169", + "id": "a0c8cbf5", "metadata": {}, "source": [ "#### 80. Consider an arbitrary array, write a function that extract a subpart with a fixed shape and centered on a given element (pad with a `fill` value when necessary) (★★★)" @@ -1354,14 +1354,14 @@ { "cell_type": "code", "execution_count": null, - "id": "e286aa38", + "id": "381fd926", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "82577004", + "id": "781fa236", "metadata": {}, "source": [ "#### 81. Consider an array Z = [1,2,3,4,5,6,7,8,9,10,11,12,13,14], how to generate an array R = [[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]? (★★★)" @@ -1370,14 +1370,14 @@ { "cell_type": "code", "execution_count": null, - "id": "299febc3", + "id": "8e84d3c2", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "19914b7e", + "id": "9c9bb0f3", "metadata": {}, "source": [ "#### 82. Compute a matrix rank (★★★)" @@ -1386,14 +1386,14 @@ { "cell_type": "code", "execution_count": null, - "id": "71b6d05e", + "id": "b75ef318", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "5b4702b1", + "id": "7d8dc135", "metadata": {}, "source": [ "#### 83. How to find the most frequent value in an array?" @@ -1402,14 +1402,14 @@ { "cell_type": "code", "execution_count": null, - "id": "47392a08", + "id": "3978a7a2", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "e2b4e6d4", + "id": "aa340126", "metadata": {}, "source": [ "#### 84. Extract all the contiguous 3x3 blocks from a random 10x10 matrix (★★★)" @@ -1418,14 +1418,14 @@ { "cell_type": "code", "execution_count": null, - "id": "ecc7884c", + "id": "bf138783", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "588931bf", + "id": "6b6d2c84", "metadata": {}, "source": [ "#### 85. Create a 2D array subclass such that Z[i,j] == Z[j,i] (★★★)" @@ -1434,14 +1434,14 @@ { "cell_type": "code", "execution_count": null, - "id": "16415e97", + "id": "155e16ce", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "3e2ada58", + "id": "7be0fe36", "metadata": {}, "source": [ "#### 86. Consider a set of p matrices wich shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)" @@ -1450,14 +1450,14 @@ { "cell_type": "code", "execution_count": null, - "id": "b830123b", + "id": "ea732c23", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "dc24b132", + "id": "a840a88f", "metadata": {}, "source": [ "#### 87. Consider a 16x16 array, how to get the block-sum (block size is 4x4)? (★★★)" @@ -1466,14 +1466,14 @@ { "cell_type": "code", "execution_count": null, - "id": "2aecf16c", + "id": "6e0c1cbe", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "bc324c05", + "id": "c2bd7385", "metadata": {}, "source": [ "#### 88. How to implement the Game of Life using numpy arrays? (★★★)" @@ -1482,14 +1482,14 @@ { "cell_type": "code", "execution_count": null, - "id": "fb2f76d6", + "id": "aea7d805", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "84266863", + "id": "4c70397b", "metadata": {}, "source": [ "#### 89. How to get the n largest values of an array (★★★)" @@ -1498,14 +1498,14 @@ { "cell_type": "code", "execution_count": null, - "id": "3b353230", + "id": "16371718", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "4f5587b9", + "id": "15ba193c", "metadata": {}, "source": [ "#### 90. Given an arbitrary number of vectors, build the cartesian product (every combinations of every item) (★★★)" @@ -1514,14 +1514,14 @@ { "cell_type": "code", "execution_count": null, - "id": "3f752a18", + "id": "c9c468d4", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "b4c22657", + "id": "ec828405", "metadata": {}, "source": [ "#### 91. How to create a record array from a regular array? (★★★)" @@ -1530,14 +1530,14 @@ { "cell_type": "code", "execution_count": null, - "id": "a0dc0426", + "id": "84eb5fba", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "bb9f1473", + "id": "d94352b6", "metadata": {}, "source": [ "#### 92. Consider a large vector Z, compute Z to the power of 3 using 3 different methods (★★★)" @@ -1546,14 +1546,14 @@ { "cell_type": "code", "execution_count": null, - "id": "0d585a57", + "id": "301ba8a8", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "3acb5b65", + "id": "7c3a9e32", "metadata": {}, "source": [ "#### 93. Consider two arrays A and B of shape (8,3) and (2,2). How to find rows of A that contain elements of each row of B regardless of the order of the elements in B? (★★★)" @@ -1562,14 +1562,14 @@ { "cell_type": "code", "execution_count": null, - "id": "f9e1e127", + "id": "777376e3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "f8f36be4", + "id": "da9d5eeb", "metadata": {}, "source": [ "#### 94. Considering a 10x3 matrix, extract rows with unequal values (e.g. [2,2,3]) (★★★)" @@ -1578,14 +1578,14 @@ { "cell_type": "code", "execution_count": null, - "id": "6caa0f63", + "id": "67dbea5c", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "2065f6b5", + "id": "f7b65fd5", "metadata": {}, "source": [ "#### 95. Convert a vector of ints into a matrix binary representation (★★★)" @@ -1594,14 +1594,14 @@ { "cell_type": "code", "execution_count": null, - "id": "8a6afb88", + "id": "127294ed", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "15953492", + "id": "2784c996", "metadata": {}, "source": [ "#### 96. Given a two dimensional array, how to extract unique rows? (★★★)" @@ -1610,14 +1610,14 @@ { "cell_type": "code", "execution_count": null, - "id": "2fbe8159", + "id": "f030595f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "95bce4fe", + "id": "71a7574c", "metadata": {}, "source": [ "#### 97. Considering 2 vectors A & B, write the einsum equivalent of inner, outer, sum, and mul function (★★★)" @@ -1626,14 +1626,14 @@ { "cell_type": "code", "execution_count": null, - "id": "07971442", + "id": "721c4e1a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "6d728760", + "id": "30f06441", "metadata": {}, "source": [ "#### 98. Considering a path described by two vectors (X,Y), how to sample it using equidistant samples (★★★)?" @@ -1642,14 +1642,14 @@ { "cell_type": "code", "execution_count": null, - "id": "2a30f221", + "id": "fb41c022", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "5b3bbdc0", + "id": "e5737276", "metadata": {}, "source": [ "#### 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. (★★★)" @@ -1658,14 +1658,14 @@ { "cell_type": "code", "execution_count": null, - "id": "eb9bad02", + "id": "68c333b0", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "6295db88", + "id": "5882e36d", "metadata": {}, "source": [ "#### 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). (★★★)" @@ -1674,7 +1674,7 @@ { "cell_type": "code", "execution_count": null, - "id": "94174a6b", + "id": "d1b566e5", "metadata": {}, "outputs": [], "source": [] diff --git a/100_Numpy_exercises.md b/100_Numpy_exercises.md index 3319bc0..edeee60 100644 --- a/100_Numpy_exercises.md +++ b/100_Numpy_exercises.md @@ -58,7 +58,7 @@ np.nan in set([np.nan]) #### 19. Create a 8x8 matrix and fill it with a checkerboard pattern (★☆☆) -#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? +#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? (★☆☆) #### 21. Create a checkerboard 8x8 matrix using the tile function (★☆☆) @@ -89,7 +89,7 @@ Z/1/1 ZZ ``` -#### 28. What are the result of the following expressions? +#### 28. What are the result of the following expressions? (★☆☆) ```python np.array(0) / np.array(0) np.array(0) // np.array(0) @@ -135,7 +135,7 @@ np.sqrt(-1) == np.emath.sqrt(-1) #### 46. Create a structured array with `x` and `y` coordinates covering the [0,1]x[0,1] area (★★☆) -#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) +#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) (★★☆) #### 48. Print the minimum and maximum representable value for each numpy scalar type (★★☆) diff --git a/100_Numpy_exercises_with_hints.md b/100_Numpy_exercises_with_hints.md index 74c1bca..5b8db89 100644 --- a/100_Numpy_exercises_with_hints.md +++ b/100_Numpy_exercises_with_hints.md @@ -58,7 +58,7 @@ np.nan in set([np.nan]) `hint: np.diag` #### 19. Create a 8x8 matrix and fill it with a checkerboard pattern (★☆☆) `hint: array[::2]` -#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? +#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? (★☆☆) `hint: np.unravel_index` #### 21. Create a checkerboard 8x8 matrix using the tile function (★☆☆) `hint: np.tile` @@ -89,7 +89,7 @@ Z/1/1 ZZ ``` `No hints provided...` -#### 28. What are the result of the following expressions? +#### 28. What are the result of the following expressions? (★☆☆) ```python np.array(0) / np.array(0) np.array(0) // np.array(0) @@ -135,7 +135,7 @@ np.sqrt(-1) == np.emath.sqrt(-1) `hint: argmax` #### 46. Create a structured array with `x` and `y` coordinates covering the [0,1]x[0,1] area (★★☆) `hint: np.meshgrid` -#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) +#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) (★★☆) `hint: np.subtract.outer` #### 48. Print the minimum and maximum representable value for each numpy scalar type (★★☆) `hint: np.iinfo, np.finfo, eps` diff --git a/100_Numpy_exercises_with_hints_with_solutions.md b/100_Numpy_exercises_with_hints_with_solutions.md index e346bb3..f8b3f3d 100644 --- a/100_Numpy_exercises_with_hints_with_solutions.md +++ b/100_Numpy_exercises_with_hints_with_solutions.md @@ -168,7 +168,7 @@ Z[1::2,::2] = 1 Z[::2,1::2] = 1 print(Z) ``` -#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? +#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? (★☆☆) `hint: np.unravel_index` ```python @@ -255,7 +255,7 @@ Z <- Z Z/1/1 ZZ ``` -#### 28. What are the result of the following expressions? +#### 28. What are the result of the following expressions? (★☆☆) ```python np.array(0) / np.array(0) np.array(0) // np.array(0) @@ -447,7 +447,7 @@ Z['x'], Z['y'] = np.meshgrid(np.linspace(0,1,5), np.linspace(0,1,5)) print(Z) ``` -#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) +#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) (★★☆) `hint: np.subtract.outer` ```python @@ -827,7 +827,7 @@ from numpy.lib import stride_tricks def rolling(a, window): shape = (a.size - window + 1, window) - strides = (a.itemsize, a.itemsize) + strides = (a.strides[0], a.strides[0]) return stride_tricks.as_strided(a, shape=shape, strides=strides) Z = rolling(np.arange(10), 3) print(Z) diff --git a/100_Numpy_exercises_with_solutions.md b/100_Numpy_exercises_with_solutions.md index da812a9..99fea53 100644 --- a/100_Numpy_exercises_with_solutions.md +++ b/100_Numpy_exercises_with_solutions.md @@ -168,7 +168,7 @@ Z[1::2,::2] = 1 Z[::2,1::2] = 1 print(Z) ``` -#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? +#### 20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? (★☆☆) ```python @@ -255,7 +255,7 @@ Z <- Z Z/1/1 ZZ ``` -#### 28. What are the result of the following expressions? +#### 28. What are the result of the following expressions? (★☆☆) ```python np.array(0) / np.array(0) np.array(0) // np.array(0) @@ -447,7 +447,7 @@ Z['x'], Z['y'] = np.meshgrid(np.linspace(0,1,5), np.linspace(0,1,5)) print(Z) ``` -#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) +#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) (★★☆) ```python @@ -827,7 +827,7 @@ from numpy.lib import stride_tricks def rolling(a, window): shape = (a.size - window + 1, window) - strides = (a.itemsize, a.itemsize) + strides = (a.strides[0], a.strides[0]) return stride_tricks.as_strided(a, shape=shape, strides=strides) Z = rolling(np.arange(10), 3) print(Z) diff --git a/100_Numpy_random.ipynb b/100_Numpy_random.ipynb index 41904f8..704e34e 100644 --- a/100_Numpy_random.ipynb +++ b/100_Numpy_random.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "9187d1fe", + "id": "bbe15f43", "metadata": {}, "source": [ "# 100 numpy exercises\n", @@ -18,7 +18,7 @@ }, { "cell_type": "markdown", - "id": "7b3fced0", + "id": "ed56e5f0", "metadata": {}, "source": [ "File automatically generated. See the documentation to update questions/answers/hints programmatically." @@ -26,7 +26,7 @@ }, { "cell_type": "markdown", - "id": "77575766", + "id": "14866554", "metadata": {}, "source": [ "Run the `initialize.py` module, then call a random question with `pick()` an hint towards its solution with\n", @@ -36,7 +36,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bcf0dd93", + "id": "af8b6f2a", "metadata": {}, "outputs": [], "source": [ @@ -46,7 +46,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f401c090", + "id": "f13ecfd7", "metadata": {}, "outputs": [], "source": [ diff --git a/source/exercises100.ktx b/source/exercises100.ktx index 5d2aea9..aaa394e 100644 --- a/source/exercises100.ktx +++ b/source/exercises100.ktx @@ -212,7 +212,7 @@ Z[::2,1::2] = 1 print(Z) < q20 -Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? +Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? (★☆☆) < h20 hint: np.unravel_index @@ -323,7 +323,7 @@ Z/1/1 ZZ < q28 -What are the result of the following expressions? +What are the result of the following expressions? (★☆☆) ```python np.array(0) / np.array(0) np.array(0) // np.array(0) @@ -572,7 +572,7 @@ Z['x'], Z['y'] = np.meshgrid(np.linspace(0,1,5), print(Z) < q47 -Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) +Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) (★★☆) < h47 hint: np.subtract.outer