Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"markdown","metadata":{"id":"HfJB9JnS9xlK"},"source":["# NumPy Exercises\n","\n","Now that we've learned about NumPy let's test your knowledge. We'll start off with a few simple tasks, and then you'll be asked some more complicated questions."]},{"cell_type":"markdown","metadata":{"id":"u9POEVg29xlM"},"source":["#### Import NumPy as np"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"yyS-PuO_9xlM"},"outputs":[],"source":["import numpy as np"]},{"cell_type":"markdown","metadata":{"id":"ehlpKUPc9xlM"},"source":["#### Create an array of 10 zeros"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"aEQkK-Dw9xlN","outputId":"1c131f2c-af63-43ef-aebb-474b4e27a4b2"},"outputs":[{"data":{"text/plain":["array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])"]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":["arr = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0])"]},{"cell_type":"markdown","metadata":{"id":"6QHp05Ei9xlN"},"source":["#### Create an array of 10 ones"]},{"cell_type":"code","execution_count":null,"metadata":{"scrolled":true,"id":"ebe9xrC29xlN","outputId":"cbbacbb1-6ba4-4a97-a0fa-a6f449b13779","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764783524704,"user_tz":-330,"elapsed":29,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[1 1 1 1 1 1 1 1 1 1]\n"]}],"source":["arr=np.full(10,1)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"id":"ziS-l3xp9xlO"},"source":["#### Create an array of 10 fives"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fFC7bqLM9xlO","outputId":"227a3fd5-c440-450d-9d5f-59494ab3ff85","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764783543104,"user_tz":-330,"elapsed":29,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[1 1 1 1 1 1 1 1 1 1]\n"]}],"source":["arr=np.full(10,1)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"id":"kBugMXlC9xlO"},"source":["#### Create an array of the integers from 10 to 50"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"JsO6qS9R9xlO","outputId":"a5c3f05f-db7d-4c37-a15c-c230529bacac","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764783558543,"user_tz":-330,"elapsed":14,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33\n"," 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50]\n"]}],"source":["arr=np.arange(10,51)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"id":"dMw4V2L79xlO"},"source":["#### Create an array of all the even integers from 10 to 50"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"4lK-5SQV9xlO","outputId":"70d187ec-b499-48f2-aaa0-5e8fc9aadd20","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764783582047,"user_tz":-330,"elapsed":26,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50]\n"]}],"source":["arr=np.arange(10,51,2)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"id":"g__F0rB39xlP"},"source":["#### Create a 3x3 matrix with values ranging from 0 to 8"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"MmVXCn0K9xlP","outputId":"25a821bc-220f-4afd-b0b2-6c77c0dfc812","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764783690729,"user_tz":-330,"elapsed":28,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[[0 1 2]\n"," [3 4 5]\n"," [6 7 8]]\n"]}],"source":["arr=np.arange(0,9)\n","arr=arr.reshape(3,3)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"id":"4YfT0aLo9xlP"},"source":["#### Create a 3x3 identity matrix"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"UHa42UpQ9xlP","outputId":"2f5b6a04-7d06-4770-cdcb-50e44762c8c3","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764783881093,"user_tz":-330,"elapsed":38,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[[1. 0. 0.]\n"," [0. 1. 0.]\n"," [0. 0. 1.]]\n"]}],"source":["arr=np.identity(3)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"id":"bfwDbjhI9xlP"},"source":["#### Use NumPy to generate a random number between 0 and 1"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Z0OroZxW9xlP","outputId":"9fb66c74-7963-44b1-853a-08afc9d479d5","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1765037674591,"user_tz":-330,"elapsed":12,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["0.7210668988630553\n"]}],"source":["print(np.random.rand())"]},{"cell_type":"markdown","metadata":{"id":"rLW0Jjzp9xlP"},"source":["#### Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"szluy14n9xlP","outputId":"1190ff62-7984-4d18-ee8b-612b03378c8a","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1765037956035,"user_tz":-330,"elapsed":15,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[-0.76238469 0.83347474 0.33969207 -1.16913462 -1.00629952 -0.02417897\n"," 0.4224093 0.86707434 1.10954394 0.32828816 0.47720936 1.14830247\n"," -0.11463323 -0.23041961 1.01458838 1.58144574 -0.08504101 -1.0065272\n"," -1.19019504 -0.57174949 0.84928131 0.51261494 0.06792625 -0.78699475\n"," -0.60657134]\n"]}],"source":["arr=np.random.randn(25)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"id":"_GhI8LYn9xlP"},"source":["#### Create the following matrix:"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"wS1ZBddV9xlP","outputId":"a0bd6e57-ee7b-45e5-9957-d64d20f2aa3b","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764785441779,"user_tz":-330,"elapsed":15,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[[0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 ]\n"," [0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 ]\n"," [0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 ]\n"," [0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 ]\n"," [0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 ]\n"," [0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 ]\n"," [0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 ]\n"," [0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 ]\n"," [0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 ]\n"," [0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1. ]]\n"]}],"source":["arr=np.arange(0.01,1.01,0.01)\n","arr=arr.reshape(10,10)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"id":"3OqA-QtL9xlQ"},"source":["#### Create an array of 20 linearly spaced points between 0 and 1:"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"FNXTugQ29xlQ","outputId":"77c82e39-3d11-4688-8019-e9467991a49a","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1765038276655,"user_tz":-330,"elapsed":11,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[[0. 0.05263158 0.10526316 0.15789474 0.21052632]\n"," [0.26315789 0.31578947 0.36842105 0.42105263 0.47368421]\n"," [0.52631579 0.57894737 0.63157895 0.68421053 0.73684211]\n"," [0.78947368 0.84210526 0.89473684 0.94736842 1. ]]\n"]}],"source":["arr=np.linspace(0,1,20)\n","arr=arr.reshape(4,5)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"id":"elx0EaxE9xlQ"},"source":["## Numpy Indexing and Selection\n","\n","Now you will be given a few matrices, and be asked to replicate the resulting matrix outputs:"]},{"cell_type":"markdown","metadata":{"id":"2Tbm9kVf9xlQ"},"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Ft8P8e249xlQ","outputId":"70f345a8-88a2-47d6-f23b-669fb606f0a0","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764786048427,"user_tz":-330,"elapsed":27,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[[ 1 2 3 4 5]\n"," [ 6 7 8 9 10]\n"," [11 12 13 14 15]\n"," [16 17 18 19 20]\n"," [21 22 23 24 25]]\n"]}],"source":["arr=np.arange(1,26)\n","arr=arr.reshape(5,5)\n","print(arr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WrcFkpGL9xlQ","outputId":"01d29308-8f64-47a3-ccf2-f827294398a4","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764786847562,"user_tz":-330,"elapsed":476,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[[12 13 14 15]\n"," [17 18 19 20]\n"," [22 23 24 25]]\n"]}],"source":["column_1=np.arange(12,23,5).reshape(-1,1)\n","column_2=np.arange(13,24,5).reshape(-1,1)\n","column_3=np.arange(14,25,5).reshape(-1,1)\n","column_4=np.arange(15,26,5).reshape(-1,1)\n","arr=np.hstack([column_1,column_2,column_3,column_4])\n","print(arr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rnUSntEa9xlQ","outputId":"d5b32dec-36c9-41a1-c6de-aaefc84ff158"},"outputs":[{"data":{"text/plain":["20"]},"execution_count":41,"metadata":{},"output_type":"execute_result"}],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"3DMBC_wp9xlQ","outputId":"88ac5531-4252-42cc-8fba-58d8946fa07a","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764786002493,"user_tz":-330,"elapsed":25,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[[ 2]\n"," [ 7]\n"," [12]]\n"]}],"source":["arr=np.arange(2,13,5)\n","arr=arr.reshape(3,1)\n","print(arr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"pGjD4HUK9xlQ","outputId":"effd7b9d-3e8e-4a0f-b892-24826c622ad6"},"outputs":[{"data":{"text/plain":["array([21, 22, 23, 24, 25])"]},"execution_count":54,"metadata":{},"output_type":"execute_result"}],"source":["arr=np.arange(16,26)\n","\n","print(arr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"dqsdpxUo9xlR","outputId":"eb61827f-c22d-4143-f92f-381f5688d8c4","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1764785860686,"user_tz":-330,"elapsed":13,"user":{"displayName":"Saksham Agarwal","userId":"14846103380388986571"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["[[16 17 18 19 20]\n"," [21 22 23 24 25]]\n"]}],"source":["arr=np.arange(16,26)\n","arr=arr.reshape(2,5)\n","print(arr)"]},{"cell_type":"markdown","metadata":{"collapsed":true,"id":"6vtHuVJU9xlf"},"source":["# Great Job!"]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.9.12"},"colab":{"provenance":[{"file_id":"1uvwMRRqMFNlaYoWGT6JhFghskgPy9dzJ","timestamp":1764783482056},{"file_id":"1PacBskAxI7FPP4LIyB_3MysbL8ArUHsV","timestamp":1764745354238},{"file_id":"19ZajGBzqADvFnQ0kzbkad_udXeAh26pj","timestamp":1731497620277}]}},"nbformat":4,"nbformat_minor":0}
1 change: 0 additions & 1 deletion Assignment 2/Assignment2_Mithil/Assignment2

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions MidEval Code/MidEval_SakshamAgarwal.ipynb

Large diffs are not rendered by default.