From a6ec72ed373daee18ee4d923048d52bb28fc20f6 Mon Sep 17 00:00:00 2001 From: Bouyahya Zied <zied.bouyahya@ec-lyon.fr> Date: Mon, 10 Mar 2025 10:43:26 +0000 Subject: [PATCH] Upload New File --- NumPy Exercises/100_Numpy_exercises.ipynb | 1657 +++++++++++++++++++++ 1 file changed, 1657 insertions(+) create mode 100644 NumPy Exercises/100_Numpy_exercises.ipynb diff --git a/NumPy Exercises/100_Numpy_exercises.ipynb b/NumPy Exercises/100_Numpy_exercises.ipynb new file mode 100644 index 0000000..5468772 --- /dev/null +++ b/NumPy Exercises/100_Numpy_exercises.ipynb @@ -0,0 +1,1657 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d46e26d4", + "metadata": {}, + "source": [ + "# 100 numpy exercises\n", + "\n", + "Source https://github.com/rougier/numpy-100/blob/master/100_Numpy_exercises.ipynb \n" + ] + }, + { + "cell_type": "markdown", + "id": "dcc6b1ac", + "metadata": {}, + "source": [ + "#### 1. Import the numpy package under the name `np` (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c52078e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "118ded29", + "metadata": {}, + "source": [ + "#### 2. Print the numpy version and the configuration (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "023a2c52", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "172b913a", + "metadata": {}, + "source": [ + "#### 3. Create a null vector of size 10 (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "df54025a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "95ee9e07", + "metadata": {}, + "source": [ + "#### 4. How to find the memory size of any array (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5c5b0950", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "45fca154", + "metadata": {}, + "source": [ + "#### 5. How to get the documentation of the numpy add function from the command line? (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fcb1248a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "674e8019", + "metadata": {}, + "source": [ + "#### 6. Create a null vector of size 10 but the fifth value which is 1 (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "452df2a7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "7685e337", + "metadata": {}, + "source": [ + "#### 7. Create a vector with values ranging from 10 to 49 (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10847d11", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "54c913ba", + "metadata": {}, + "source": [ + "#### 8. Reverse a vector (first element becomes last) (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "34722e83", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "8e72fd08", + "metadata": {}, + "source": [ + "#### 9. Create a 3x3 matrix with values ranging from 0 to 8 (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e18eef56", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "088424fc", + "metadata": {}, + "source": [ + "#### 10. Find indices of non-zero elements from [1,2,0,0,4,0] (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9a402d06", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "3f347de9", + "metadata": {}, + "source": [ + "#### 11. Create a 3x3 identity matrix (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e38459c2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "24e98f25", + "metadata": {}, + "source": [ + "#### 12. Create a 3x3x3 array with random values (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "94752bb3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "7cbca2cc", + "metadata": {}, + "source": [ + "#### 13. Create a 10x10 array with random values and find the minimum and maximum values (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c0643b1f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "6cab4cbb", + "metadata": {}, + "source": [ + "#### 14. Create a random vector of size 30 and find the mean value (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e922a524", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "72053be8", + "metadata": {}, + "source": [ + "#### 15. Create a 2d array with 1 on the border and 0 inside (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6bc84dfe", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "86b0206b", + "metadata": {}, + "source": [ + "#### 16. How to add a border (filled with 0's) around an existing array? (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41e66e3e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "98a45574", + "metadata": {}, + "source": [ + "#### 17. What is the result of the following expression? (★☆☆)\n", + "```python\n", + "0 * np.nan\n", + "np.nan == np.nan\n", + "np.inf > np.nan\n", + "np.nan - np.nan\n", + "np.nan in set([np.nan])\n", + "0.3 == 3 * 0.1\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7eb533d5", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "1486619a", + "metadata": {}, + "source": [ + "#### 18. Create a 5x5 matrix with values 1,2,3,4 just below the diagonal (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2b9fb59c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "319287fd", + "metadata": {}, + "source": [ + "#### 19. Create a 8x8 matrix and fill it with a checkerboard pattern (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "299f5e60", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "fb1686ed", + "metadata": {}, + "source": [ + "#### 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": "22888cc4", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "137ea278", + "metadata": {}, + "source": [ + "#### 21. Create a checkerboard 8x8 matrix using the tile function (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9cb81fe1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "9319f5a1", + "metadata": {}, + "source": [ + "#### 22. Normalize a 5x5 random matrix (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fcdc0459", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "f1902fef", + "metadata": {}, + "source": [ + "#### 23. Create a custom dtype that describes a color as four unsigned bytes (RGBA) (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7445cb2d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "3f34bd2a", + "metadata": {}, + "source": [ + "#### 24. Multiply a 5x3 matrix by a 3x2 matrix (real matrix product) (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec8bd6da", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "b1919ba3", + "metadata": {}, + "source": [ + "#### 25. Given a 1D array, negate all elements which are between 3 and 8, in place. (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5b63b63b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "fb1daa27", + "metadata": {}, + "source": [ + "#### 26. What is the output of the following script? (★☆☆)\n", + "```python\n", + "# Author: Jake VanderPlas\n", + "\n", + "print(sum(range(5),-1))\n", + "from numpy import *\n", + "print(sum(range(5),-1))\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "52a34d3d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "89b7e7a7", + "metadata": {}, + "source": [ + "#### 27. Consider an integer vector Z, which of these expressions are legal? (★☆☆)\n", + "```python\n", + "Z**Z\n", + "2 << Z >> 2\n", + "Z <- Z\n", + "1j*Z\n", + "Z/1/1\n", + "Z<Z>Z\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "451181cf", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "8c7601c6", + "metadata": {}, + "source": [ + "#### 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", + "np.array([np.nan]).astype(int).astype(float)\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "52983a0b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "06c9164d", + "metadata": {}, + "source": [ + "#### 29. How to round away from zero a float array ? (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4cce0af8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "52235994", + "metadata": {}, + "source": [ + "#### 30. How to find common values between two arrays? (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "27eff6b1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "7e6f7d78", + "metadata": {}, + "source": [ + "#### 31. How to ignore all numpy warnings (not recommended)? (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1bdde6e1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "b001277e", + "metadata": {}, + "source": [ + "#### 32. Is the following expressions true? (★☆☆)\n", + "```python\n", + "np.sqrt(-1) == np.emath.sqrt(-1)\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d8673bdf", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "b9a5ff84", + "metadata": {}, + "source": [ + "#### 33. How to get the dates of yesterday, today and tomorrow? (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f33f9cc2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "f8e96e58", + "metadata": {}, + "source": [ + "#### 34. How to get all the dates corresponding to the month of July 2016? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3927a8e8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "557c163e", + "metadata": {}, + "source": [ + "#### 35. How to compute ((A+B)*(-A/2)) in place (without copy)? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3c2f59ac", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "14c05852", + "metadata": {}, + "source": [ + "#### 36. Extract the integer part of a random array of positive numbers using 4 different methods (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b7d2937", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "003b8721", + "metadata": {}, + "source": [ + "#### 37. Create a 5x5 matrix with row values ranging from 0 to 4 (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63c75db0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "8e71dc21", + "metadata": {}, + "source": [ + "#### 38. Consider a generator function that generates 10 integers and use it to build an array (★☆☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f6aefd94", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "b7f03449", + "metadata": {}, + "source": [ + "#### 39. Create a vector of size 10 with values ranging from 0 to 1, both excluded (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a27cd904", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "043156c5", + "metadata": {}, + "source": [ + "#### 40. Create a random vector of size 10 and sort it (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ae5eb58", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "4f7e8f3f", + "metadata": {}, + "source": [ + "#### 41. How to sum a small array faster than np.sum? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "88790af3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "13d1ca52", + "metadata": {}, + "source": [ + "#### 42. Consider two random array A and B, check if they are equal (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ca6dd579", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "cf7cca6d", + "metadata": {}, + "source": [ + "#### 43. Make an array immutable (read-only) (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cbbb8917", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "37b0828f", + "metadata": {}, + "source": [ + "#### 44. Consider a random 10x2 matrix representing cartesian coordinates, convert them to polar coordinates (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a89969af", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "b7d7dd80", + "metadata": {}, + "source": [ + "#### 45. Create random vector of size 10 and replace the maximum value by 0 (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8403a440", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "b47e5837", + "metadata": {}, + "source": [ + "#### 46. Create a structured array with `x` and `y` coordinates covering the [0,1]x[0,1] area (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42c72e94", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "8c7946ee", + "metadata": {}, + "source": [ + "#### 47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj)) (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "26b93f06", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "3e898e5f", + "metadata": {}, + "source": [ + "#### 48. Print the minimum and maximum representable value for each numpy scalar type (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "afd1ae18", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "6fe6133b", + "metadata": {}, + "source": [ + "#### 49. How to print all the values of an array? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5764ec92", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "7ee2dacc", + "metadata": {}, + "source": [ + "#### 50. How to find the closest value (to a given scalar) in a vector? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "742518ef", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "cfeda6ba", + "metadata": {}, + "source": [ + "#### 51. Create a structured array representing a position (x,y) and a color (r,g,b) (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9fcbd031", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "b97e75b5", + "metadata": {}, + "source": [ + "#### 52. Consider a random vector with shape (100,2) representing coordinates, find point by point distances (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c58a45b6", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "291e0bb9", + "metadata": {}, + "source": [ + "#### 53. How to convert a float (32 bits) array into an integer (32 bits) in place?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2f3e6c00", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "1e305e92", + "metadata": {}, + "source": [ + "#### 54. How to read the following file? (★★☆)\n", + "```\n", + "1, 2, 3, 4, 5\n", + "6, , , 7, 8\n", + " , , 9,10,11\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "753024cb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "94a8ad69", + "metadata": {}, + "source": [ + "#### 55. What is the equivalent of enumerate for numpy arrays? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ae45249f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "72b340c9", + "metadata": {}, + "source": [ + "#### 56. Generate a generic 2D Gaussian-like array (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a80e5c9b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "86550d61", + "metadata": {}, + "source": [ + "#### 57. How to randomly place p elements in a 2D array? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "db9f2582", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "153f8cfa", + "metadata": {}, + "source": [ + "#### 58. Subtract the mean of each row of a matrix (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8301cb12", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "f4038090", + "metadata": {}, + "source": [ + "#### 59. How to sort an array by the nth column? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb5745df", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "20d2a462", + "metadata": {}, + "source": [ + "#### 60. How to tell if a given 2D array has null columns? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b92b7316", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "bb2aa49b", + "metadata": {}, + "source": [ + "#### 61. Find the nearest value from a given value in an array (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b62e59c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "1a950e1a", + "metadata": {}, + "source": [ + "#### 62. Considering two arrays with shape (1,3) and (3,1), how to compute their sum using an iterator? (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cad1d01b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "165b3a20", + "metadata": {}, + "source": [ + "#### 63. Create an array class that has a name attribute (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "666bf983", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "87f85b12", + "metadata": {}, + "source": [ + "#### 64. Consider a given vector, how to add 1 to each element indexed by a second vector (be careful with repeated indices)? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "03ee4c88", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "1cda27c4", + "metadata": {}, + "source": [ + "#### 65. How to accumulate elements of a vector (X) to an array (F) based on an index list (I)? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aee2c782", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "1db205db", + "metadata": {}, + "source": [ + "#### 66. Considering a (w,h,3) image of (dtype=ubyte), compute the number of unique colors (★★☆)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "43204f35", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "ebaf1222", + "metadata": {}, + "source": [ + "#### 67. Considering a four dimensions array, how to get sum over the last two axis at once? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aabbbab9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "2dfb4033", + "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? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a9c2287", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "7035c626", + "metadata": {}, + "source": [ + "#### 69. How to get the diagonal of a dot product? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f6af16c1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "8f73f0e5", + "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? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b0cabc11", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "bafaa79e", + "metadata": {}, + "source": [ + "#### 71. Consider an array of dimension (5,5,3), how to mulitply it by an array with dimensions (5,5)? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d441e30b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "80a9ac82", + "metadata": {}, + "source": [ + "#### 72. How to swap two rows of an array? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1aee2791", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "5e53d68c", + "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 (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2f975322", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "f85da603", + "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? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8c476a73", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "a2330e6c", + "metadata": {}, + "source": [ + "#### 75. How to compute averages using a sliding window over an array? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35e5e9f5", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "87698de8", + "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]) (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "753763ed", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "b8417b15", + "metadata": {}, + "source": [ + "#### 77. How to negate a boolean, or to change the sign of a float inplace? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3cad31b2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "37a49831", + "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])? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "df95dce8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "f5ae032f", + "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])? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f5ae2e9b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "6bc35ba2", + "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) (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2ad8db75", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "d17818f7", + "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]]? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "97deb72f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "67f526e6", + "metadata": {}, + "source": [ + "#### 82. Compute a matrix rank (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d70bed5b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "0a3fb55f", + "metadata": {}, + "source": [ + "#### 83. How to find the most frequent value in an array?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b0647d07", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "cb0ac341", + "metadata": {}, + "source": [ + "#### 84. Extract all the contiguous 3x3 blocks from a random 10x10 matrix (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "91798923", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "c2a9da0d", + "metadata": {}, + "source": [ + "#### 85. Create a 2D array subclass such that Z[i,j] == Z[j,i] (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f9b027ff", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "718ac868", + "metadata": {}, + "source": [ + "#### 86. Consider a set of p matrices with 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)) (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4de05217", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "a6eda6f8", + "metadata": {}, + "source": [ + "#### 87. Consider a 16x16 array, how to get the block-sum (block size is 4x4)? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "286b8db5", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "625aa611", + "metadata": {}, + "source": [ + "#### 88. How to implement the Game of Life using numpy arrays? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a01c1ff2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "ca3dde4a", + "metadata": {}, + "source": [ + "#### 89. How to get the n largest values of an array (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d14148c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "e233805e", + "metadata": {}, + "source": [ + "#### 90. Given an arbitrary number of vectors, build the cartesian product (every combinations of every item) (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17638e13", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "c163f115", + "metadata": {}, + "source": [ + "#### 91. How to create a record array from a regular array? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da402514", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "049c006e", + "metadata": {}, + "source": [ + "#### 92. Consider a large vector Z, compute Z to the power of 3 using 3 different methods (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "96ce278a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "6e652635", + "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? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f429d6d4", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "33c4755d", + "metadata": {}, + "source": [ + "#### 94. Considering a 10x3 matrix, extract rows with unequal values (e.g. [2,2,3]) (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29507586", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "c9fe158d", + "metadata": {}, + "source": [ + "#### 95. Convert a vector of ints into a matrix binary representation (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "58209fb7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "f60086c9", + "metadata": {}, + "source": [ + "#### 96. Given a two dimensional array, how to extract unique rows? (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "787b6e4c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "0f5e1299", + "metadata": {}, + "source": [ + "#### 97. Considering 2 vectors A & B, write the einsum equivalent of inner, outer, sum, and mul function (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd2a8214", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "a04dd898", + "metadata": {}, + "source": [ + "#### 98. Considering a path described by two vectors (X,Y), how to sample it using equidistant samples (★★★)?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12d9c30f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "b45bf2ae", + "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. (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f4179f4a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "d92b6592", + "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). (★★★)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "256ebe30", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} -- GitLab