diff --git a/Rohit-2020-09-24.ipynb b/Rohit-2020-09-24.ipynb new file mode 100644 index 0000000..114534d --- /dev/null +++ b/Rohit-2020-09-24.ipynb @@ -0,0 +1,991 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.8.3" + }, + "colab": { + "name": "Rohit-2020-09-24.ipynb", + "provenance": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "ysZ_Zc7jXQLm" + }, + "source": [ + "# GRAY INTERFACE \n", + "\n", + "## HackSlash " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SeiOUaMLXQLo" + }, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0VcY6iWPXQLu" + }, + "source": [ + "# NumPy" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sveBt_S5XQLv" + }, + "source": [ + "## Exercise 1: Creating Numpy arrays" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fnIyQKKoXQLx" + }, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FKz52UNSXQLy" + }, + "source": [ + "#### Write & Run CODE to answer each of the given problem statement.\n", + "##### Note that Sample Output of the problem statement is also given for reference. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UPzeXKd-XQL0" + }, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JR3ziOY4XQL1" + }, + "source": [ + "## Import numpy" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "xorAeajEXQL3" + }, + "source": [ + "import numpy as np" + ], + "execution_count": 2, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_9FTYkoYXQL_" + }, + "source": [ + "## Create Numpy arrays from Python list\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "v9ebkdjTXQMB" + }, + "source": [ + "#### Create Numpy 1d array from list\n", + "\n", + "`array([1, 2, 3])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "uxR42QFrXQMC" + }, + "source": [ + "list_1d = np.array[1,2,3]" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "jnwKmdKIXQMI", + "outputId": "c760bd50-451c-444c-b4c1-45c2344b799f" + }, + "source": [ + "list_1d" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[1, 2, 3]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 3 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Nku-ubYJXQMR" + }, + "source": [ + "#### Create Numpy 2d array from list\n", + "\n", + "`array([[1, 2, 3],\n", + " [4, 5, 6]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "kNVCtO9aXQMT" + }, + "source": [ + "list_2d = np.array([[1,2,3],\n", + " [4,5,6]])" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "07BN26LPXQMY", + "outputId": "fd475be6-6b2c-47c6-b321-7f4266b2b941" + }, + "source": [ + "list_2d" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1, 2, 3],\n", + " [4, 5, 6]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 6 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5dKPATOKXQMg" + }, + "source": [ + "#### Create Numpy 3d array from list" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GMOEEx7eXQMi" + }, + "source": [ + "`array([[[1, 2, 3],\n", + " [4, 5, 6]],\n", + " [[1, 2, 3],\n", + " [4, 5, 6]]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PrcKqmOkXQMj" + }, + "source": [ + "list_3d = np.array([[[1,2,3],\n", + " [4,5,6]], \n", + " [[1,2,3],\n", + " [4,5,6]]])" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "OT3ILqxOXQMq", + "outputId": "25f5fcdf-a5e9-472f-a570-dc7a9eea2a4a" + }, + "source": [ + "list_3d" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[[1, 2, 3],\n", + " [4, 5, 6]],\n", + "\n", + " [[1, 2, 3],\n", + " [4, 5, 6]]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 8 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Ic_ihn5RXQMy" + }, + "source": [ + "-----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3nK7dFFSXQMz" + }, + "source": [ + "## Create Numpy arrays using functions" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cZiD_nJqXQM1" + }, + "source": [ + "#### Create a Numpy 1d array of 10 zeros \n", + "\n", + " `array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "VNejzKqOXQM2", + "outputId": "c594ed73-c97e-4702-cf26-2861c234378c" + }, + "source": [ + "zeros = np.zeros(10)\n", + "zeros" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 9 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2AQwry-EXQM9" + }, + "source": [ + "#### Create a Numpy 1d array of 10 ones\n", + "\n", + "`array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "scrolled": true, + "id": "DI1iHZ1MXQNB", + "outputId": "4862d3f1-3eca-403a-e514-88034aab76a3" + }, + "source": [ + "ones = np.ones(10)\n", + "ones" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 10 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "F0DmLwW6XQNJ" + }, + "source": [ + "#### Create a Numpy 1d array of 10 fives\n", + "\n", + "`array([5, 5, 5, 5, 5, 5, 5, 5, 5, 5])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "2jEuCWsnXQNL", + "outputId": "151f8cb2-f5e5-4067-fde6-1e7fffd8125b" + }, + "source": [ + "fives = ones*5\n", + "fives.astype(int)" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([5, 5, 5, 5, 5, 5, 5, 5, 5, 5])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 13 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "e7Im8l-SXQNR" + }, + "source": [ + "#### Create a Numpy 1d array consisting of all the integers from 10 to 50\n", + "\n", + "`array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n", + " 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\n", + " 44, 45, 46, 47, 48, 49, 50])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "F4P_lpCpXQNT", + "outputId": "30d7f654-a3e4-45a4-e687-ceffd49a1dc2" + }, + "source": [ + "a1 = np.arange(10, 50)\n", + "a1" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n", + " 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\n", + " 44, 45, 46, 47, 48, 49])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 17 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "S8xN5LSmXQNZ" + }, + "source": [ + "#### Create a Numpy 1d array consisting of all the even integers only from 10 to 50\n", + "\n", + "`array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,\n", + " 44, 46, 48, 50])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "nvFKpXqlXQNb", + "outputId": "f23b9d3b-f3ea-4cb1-a82a-d1cf3f68f31f" + }, + "source": [ + "a2 = np.arange(10, 50, 2)\n", + "a2" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,\n", + " 44, 46, 48])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 18 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "C1Ljd4C7XQNj" + }, + "source": [ + "#### Create a Numpy 2d array with shape (3,3) having all entries as 1\n", + "\n", + "`array([[1., 1., 1.],\n", + " [1., 1., 1.],\n", + " [1., 1., 1.]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PJ4tous6XQNk", + "outputId": "2dd9f0db-a315-435a-8b97-a0950a5fa5eb" + }, + "source": [ + "a3 = np.ones((3,3))\n", + "a3" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 1., 1.],\n", + " [1., 1., 1.],\n", + " [1., 1., 1.]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 19 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LzW6gWxRXQNp" + }, + "source": [ + "#### Create a Numpy 2d array with shape (10,10) having all diagonal entries as 1 and all others as 0\n", + "\n", + "`array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 1., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 1., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 1., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Jktw1-IuXQNq", + "outputId": "8124bf1d-e304-4a2d-ff4e-60219e7ddf5e" + }, + "source": [ + "a4 = np.zeros((10, 10))\n", + "np.fill_diagonal(a4, 1)\n", + "a4" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 1., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 1., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 1., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 27 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LPRJ-r8oXQNv" + }, + "source": [ + "#### Create a Numpy 2d array with shape (5,6) consisting of values ranging from 1 to 30\n", + "\n", + "`array([[ 1, 2, 3, 4, 5, 6],\n", + " [ 7, 8, 9, 10, 11, 12],\n", + " [13, 14, 15, 16, 17, 18],\n", + " [19, 20, 21, 22, 23, 24],\n", + " [25, 26, 27, 28, 29, 30]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "0wbQZ01ZXQNw", + "outputId": "cd67b846-132a-45ef-f155-e579a0fd4563" + }, + "source": [ + "a5 = np.arange(1, 31).reshape(5, 6)\n", + "a5" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 1, 2, 3, 4, 5, 6],\n", + " [ 7, 8, 9, 10, 11, 12],\n", + " [13, 14, 15, 16, 17, 18],\n", + " [19, 20, 21, 22, 23, 24],\n", + " [25, 26, 27, 28, 29, 30]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 37 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cfqhkD61XQN1" + }, + "source": [ + "#### Create a Numpy 1d array consisting of a random number between 0 and 1\n", + "\n", + "`array([0.42829726])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "F69msW1lXQN2", + "outputId": "501ee287-a66f-4885-c307-e3d00a3cf676" + }, + "source": [ + "a6 = np.random.random(1)\n", + "a6" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0.07729339])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 41 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TMRKw8DSXQN7" + }, + "source": [ + "#### Create a Numpy 1d array consisting of six *random* numbers between 0 and 1\n", + "\n", + "`array([0.48986417, 0.61869789, 0.83943457, 0.94889576, 0.79561515, 0.28859058])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "gF-6VJb3XQN9", + "outputId": "08b401f2-4fe4-4baa-f710-96f2b47540ea" + }, + "source": [ + "a7 = np.random.random(6)\n", + "a7" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0.31603255, 0.94442351, 0.67546733, 0.49993517, 0.12707087,\n", + " 0.49862089])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 40 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tXPgOjFmXQOD" + }, + "source": [ + "#### Create a Numpy 2d array of shape (2,3) consisting of five *random* numbers between 0 and 1\n", + "\n", + "`array([[0.3991418 , 0.62631826, 0.82763635],\n", + " [0.9232742 , 0.08517427, 0.20155819]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "hfaVKpSfXQOF", + "outputId": "807fa887-49af-43ec-fbdb-64c02a422a38" + }, + "source": [ + "a8 = np.random.random(size=(2, 3))\n", + "a8" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[0.39039111, 0.82852577, 0.76315103],\n", + " [0.82700325, 0.08247063, 0.13188691]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 43 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Cf6WLC80XQOK" + }, + "source": [ + "#### Create a Numpy 1d array consisting of 25 random numbers sampled from a *Standard Normal Distribution*\n", + "\n", + "`array([-0.01804177, -0.11468092, -0.4790744 , -0.44706856, 0.49891779,\n", + " 1.53806364, -1.03689237, 0.04379123, -0.6659274 , -0.54294319,\n", + " -0.08016372, -0.64441992, -0.12417271, 0.89901988, -0.08695241,\n", + " 0.23540321, 1.77803936, 1.39912268, 0.19886053, -0.56546787,\n", + " 0.09538678, -0.47930312, 2.15532489, 0.62643712, 1.19941788])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "8O_rJstOXQOL", + "outputId": "9822152c-5351-4e72-b43f-31d181e4dc4a" + }, + "source": [ + "a9 = np.random.normal(0, 1, 25)\n", + "a9" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([-1.28311083, -0.51166075, -1.16968094, 1.40954369, 0.69034305,\n", + " -1.24372526, -0.27167964, 0.62141372, -1.49565467, -0.45851534,\n", + " 0.36675755, 0.7458972 , 0.2076125 , 1.4570458 , -0.2218839 ,\n", + " -1.38782674, -1.85398042, -0.45296259, 0.91931724, 0.12496521,\n", + " -1.27608387, -0.60804623, 0.43132898, -1.44829818, -0.73356109])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 45 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ANYwg3TgXQOQ" + }, + "source": [ + "#### Generate a *random* integer between 1 and 50\n", + "\n", + "`32`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "_5zQOBImXQOT", + "outputId": "aaf7a36f-a343-4f92-ede7-30f73735f6b9" + }, + "source": [ + "a10 = np.random.randint(1, 50)\n", + "a10" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "36" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 47 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WDhy2BFOXQOb" + }, + "source": [ + "#### Create a Numpy 1d array consisting of five *random* integers between 1 and 50\n", + "\n", + "`array([36, 30, 32, 14, 2])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "tsljNldUXQOc", + "outputId": "14723c71-0b7d-4ab2-faf6-7fb291529576" + }, + "source": [ + "a11 = np.random.randint(1, 50, size=(5))\n", + "a11" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([41, 43, 23, 28, 14])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 48 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tZcYx6kVXQOg" + }, + "source": [ + "#### Create a Numpy array consisting of 20 linearly spaced points between 0 and 1\n", + "\n", + "`array([ 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. ])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "41ed4-0rXQOh", + "outputId": "bf01dd86-ebc5-440e-ad0d-05bdb0c6c5e1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 87 + } + }, + "source": [ + "a12 = np.linspace(0, 1, num=20)\n", + "a12" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([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. ])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 3 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SmGanf3EXQOp" + }, + "source": [ + "#### Create the following Numpy 2d array:\n", + "\n", + "`array([[ 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. ]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "srIwqxEgXQOq", + "outputId": "6ffc7798-9e50-4f61-e4a9-8c9af9459586" + }, + "source": [ + "a13 = np.arange(0.01, 1.01, 0.01).reshape(10, 10)\n", + "a13" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[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. ]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 56 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LHQU5IEnXQOu" + }, + "source": [ + "-----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "id": "XURw5nAGXQOv" + }, + "source": [ + "# Great Job!" + ] + } + ] +} \ No newline at end of file diff --git a/Rohit_assignment_1.ipynb b/Rohit_assignment_1.ipynb new file mode 100644 index 0000000..48f50d4 --- /dev/null +++ b/Rohit_assignment_1.ipynb @@ -0,0 +1,1066 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.8.3" + }, + "colab": { + "name": "Rohit-2020-09-24.ipynb", + "provenance": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "ysZ_Zc7jXQLm", + "colab_type": "text" + }, + "source": [ + "# GRAY INTERFACE \n", + "\n", + "## HackSlash " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SeiOUaMLXQLo", + "colab_type": "text" + }, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0VcY6iWPXQLu", + "colab_type": "text" + }, + "source": [ + "# NumPy" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sveBt_S5XQLv", + "colab_type": "text" + }, + "source": [ + "## Exercise 1: Creating Numpy arrays" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fnIyQKKoXQLx", + "colab_type": "text" + }, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FKz52UNSXQLy", + "colab_type": "text" + }, + "source": [ + "#### Write & Run CODE to answer each of the given problem statement.\n", + "##### Note that Sample Output of the problem statement is also given for reference. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UPzeXKd-XQL0", + "colab_type": "text" + }, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JR3ziOY4XQL1", + "colab_type": "text" + }, + "source": [ + "## Import numpy" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "xorAeajEXQL3", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import numpy as np" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_9FTYkoYXQL_", + "colab_type": "text" + }, + "source": [ + "## Create Numpy arrays from Python list\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "v9ebkdjTXQMB", + "colab_type": "text" + }, + "source": [ + "#### Create Numpy 1d array from list\n", + "\n", + "`array([1, 2, 3])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "uxR42QFrXQMC", + "colab_type": "code", + "colab": {} + }, + "source": [ + "list_1d = np.array[1,2,3]" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "jnwKmdKIXQMI", + "colab_type": "code", + "colab": {}, + "outputId": "c760bd50-451c-444c-b4c1-45c2344b799f" + }, + "source": [ + "list_1d" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[1, 2, 3]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 3 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Nku-ubYJXQMR", + "colab_type": "text" + }, + "source": [ + "#### Create Numpy 2d array from list\n", + "\n", + "`array([[1, 2, 3],\n", + " [4, 5, 6]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "kNVCtO9aXQMT", + "colab_type": "code", + "colab": {} + }, + "source": [ + "list_2d = np.array([[1,2,3],\n", + " [4,5,6]])" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "07BN26LPXQMY", + "colab_type": "code", + "colab": {}, + "outputId": "fd475be6-6b2c-47c6-b321-7f4266b2b941" + }, + "source": [ + "list_2d" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1, 2, 3],\n", + " [4, 5, 6]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 6 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5dKPATOKXQMg", + "colab_type": "text" + }, + "source": [ + "#### Create Numpy 3d array from list" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GMOEEx7eXQMi", + "colab_type": "text" + }, + "source": [ + "`array([[[1, 2, 3],\n", + " [4, 5, 6]],\n", + " [[1, 2, 3],\n", + " [4, 5, 6]]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PrcKqmOkXQMj", + "colab_type": "code", + "colab": {} + }, + "source": [ + "list_3d = np.array([[[1,2,3],\n", + " [4,5,6]], \n", + " [[1,2,3],\n", + " [4,5,6]]])" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "OT3ILqxOXQMq", + "colab_type": "code", + "colab": {}, + "outputId": "25f5fcdf-a5e9-472f-a570-dc7a9eea2a4a" + }, + "source": [ + "list_3d" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[[1, 2, 3],\n", + " [4, 5, 6]],\n", + "\n", + " [[1, 2, 3],\n", + " [4, 5, 6]]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 8 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Ic_ihn5RXQMy", + "colab_type": "text" + }, + "source": [ + "-----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3nK7dFFSXQMz", + "colab_type": "text" + }, + "source": [ + "## Create Numpy arrays using functions" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cZiD_nJqXQM1", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 1d array of 10 zeros \n", + "\n", + " `array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "VNejzKqOXQM2", + "colab_type": "code", + "colab": {}, + "outputId": "c594ed73-c97e-4702-cf26-2861c234378c" + }, + "source": [ + "zeros = np.zeros(10)\n", + "zeros" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 9 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2AQwry-EXQM9", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 1d array of 10 ones\n", + "\n", + "`array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "scrolled": true, + "id": "DI1iHZ1MXQNB", + "colab_type": "code", + "colab": {}, + "outputId": "4862d3f1-3eca-403a-e514-88034aab76a3" + }, + "source": [ + "ones = np.ones(10)\n", + "ones" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 10 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "F0DmLwW6XQNJ", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 1d array of 10 fives\n", + "\n", + "`array([5, 5, 5, 5, 5, 5, 5, 5, 5, 5])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "2jEuCWsnXQNL", + "colab_type": "code", + "colab": {}, + "outputId": "151f8cb2-f5e5-4067-fde6-1e7fffd8125b" + }, + "source": [ + "fives = ones*5\n", + "fives.astype(int)" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([5, 5, 5, 5, 5, 5, 5, 5, 5, 5])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 13 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "e7Im8l-SXQNR", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 1d array consisting of all the integers from 10 to 50\n", + "\n", + "`array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n", + " 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\n", + " 44, 45, 46, 47, 48, 49, 50])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "F4P_lpCpXQNT", + "colab_type": "code", + "colab": {}, + "outputId": "30d7f654-a3e4-45a4-e687-ceffd49a1dc2" + }, + "source": [ + "a1 = np.arange(10, 50)\n", + "a1" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n", + " 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\n", + " 44, 45, 46, 47, 48, 49])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 17 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "S8xN5LSmXQNZ", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 1d array consisting of all the even integers only from 10 to 50\n", + "\n", + "`array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,\n", + " 44, 46, 48, 50])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "nvFKpXqlXQNb", + "colab_type": "code", + "colab": {}, + "outputId": "f23b9d3b-f3ea-4cb1-a82a-d1cf3f68f31f" + }, + "source": [ + "a2 = np.arange(10, 50, 2)\n", + "a2" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,\n", + " 44, 46, 48])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 18 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "C1Ljd4C7XQNj", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 2d array with shape (3,3) having all entries as 1\n", + "\n", + "`array([[1., 1., 1.],\n", + " [1., 1., 1.],\n", + " [1., 1., 1.]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PJ4tous6XQNk", + "colab_type": "code", + "colab": {}, + "outputId": "2dd9f0db-a315-435a-8b97-a0950a5fa5eb" + }, + "source": [ + "a3 = np.ones((3,3))\n", + "a3" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 1., 1.],\n", + " [1., 1., 1.],\n", + " [1., 1., 1.]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 19 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LzW6gWxRXQNp", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 2d array with shape (10,10) having all diagonal entries as 1 and all others as 0\n", + "\n", + "`array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 1., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 1., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 1., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Jktw1-IuXQNq", + "colab_type": "code", + "colab": {}, + "outputId": "8124bf1d-e304-4a2d-ff4e-60219e7ddf5e" + }, + "source": [ + "a4 = np.zeros((10, 10))\n", + "np.fill_diagonal(a4, 1)\n", + "a4" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 1., 0., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 1., 0., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 1., 0., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],\n", + " [0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 27 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LPRJ-r8oXQNv", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 2d array with shape (5,6) consisting of values ranging from 1 to 30\n", + "\n", + "`array([[ 1, 2, 3, 4, 5, 6],\n", + " [ 7, 8, 9, 10, 11, 12],\n", + " [13, 14, 15, 16, 17, 18],\n", + " [19, 20, 21, 22, 23, 24],\n", + " [25, 26, 27, 28, 29, 30]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "0wbQZ01ZXQNw", + "colab_type": "code", + "colab": {}, + "outputId": "cd67b846-132a-45ef-f155-e579a0fd4563" + }, + "source": [ + "a5 = np.arange(1, 31).reshape(5, 6)\n", + "a5" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 1, 2, 3, 4, 5, 6],\n", + " [ 7, 8, 9, 10, 11, 12],\n", + " [13, 14, 15, 16, 17, 18],\n", + " [19, 20, 21, 22, 23, 24],\n", + " [25, 26, 27, 28, 29, 30]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 37 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cfqhkD61XQN1", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 1d array consisting of a random number between 0 and 1\n", + "\n", + "`array([0.42829726])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "F69msW1lXQN2", + "colab_type": "code", + "colab": {}, + "outputId": "501ee287-a66f-4885-c307-e3d00a3cf676" + }, + "source": [ + "a6 = np.random.random(1)\n", + "a6" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0.07729339])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 41 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TMRKw8DSXQN7", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 1d array consisting of six *random* numbers between 0 and 1\n", + "\n", + "`array([0.48986417, 0.61869789, 0.83943457, 0.94889576, 0.79561515, 0.28859058])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "gF-6VJb3XQN9", + "colab_type": "code", + "colab": {}, + "outputId": "08b401f2-4fe4-4baa-f710-96f2b47540ea" + }, + "source": [ + "a7 = np.random.random(6)\n", + "a7" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0.31603255, 0.94442351, 0.67546733, 0.49993517, 0.12707087,\n", + " 0.49862089])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 40 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tXPgOjFmXQOD", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 2d array of shape (2,3) consisting of five *random* numbers between 0 and 1\n", + "\n", + "`array([[0.3991418 , 0.62631826, 0.82763635],\n", + " [0.9232742 , 0.08517427, 0.20155819]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "hfaVKpSfXQOF", + "colab_type": "code", + "colab": {}, + "outputId": "807fa887-49af-43ec-fbdb-64c02a422a38" + }, + "source": [ + "a8 = np.random.random(size=(2, 3))\n", + "a8" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[0.39039111, 0.82852577, 0.76315103],\n", + " [0.82700325, 0.08247063, 0.13188691]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 43 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Cf6WLC80XQOK", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 1d array consisting of 25 random numbers sampled from a *Standard Normal Distribution*\n", + "\n", + "`array([-0.01804177, -0.11468092, -0.4790744 , -0.44706856, 0.49891779,\n", + " 1.53806364, -1.03689237, 0.04379123, -0.6659274 , -0.54294319,\n", + " -0.08016372, -0.64441992, -0.12417271, 0.89901988, -0.08695241,\n", + " 0.23540321, 1.77803936, 1.39912268, 0.19886053, -0.56546787,\n", + " 0.09538678, -0.47930312, 2.15532489, 0.62643712, 1.19941788])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "8O_rJstOXQOL", + "colab_type": "code", + "colab": {}, + "outputId": "9822152c-5351-4e72-b43f-31d181e4dc4a" + }, + "source": [ + "a9 = np.random.normal(0, 1, 25)\n", + "a9" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([-1.28311083, -0.51166075, -1.16968094, 1.40954369, 0.69034305,\n", + " -1.24372526, -0.27167964, 0.62141372, -1.49565467, -0.45851534,\n", + " 0.36675755, 0.7458972 , 0.2076125 , 1.4570458 , -0.2218839 ,\n", + " -1.38782674, -1.85398042, -0.45296259, 0.91931724, 0.12496521,\n", + " -1.27608387, -0.60804623, 0.43132898, -1.44829818, -0.73356109])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 45 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ANYwg3TgXQOQ", + "colab_type": "text" + }, + "source": [ + "#### Generate a *random* integer between 1 and 50\n", + "\n", + "`32`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "_5zQOBImXQOT", + "colab_type": "code", + "colab": {}, + "outputId": "aaf7a36f-a343-4f92-ede7-30f73735f6b9" + }, + "source": [ + "a10 = np.random.randint(1, 50)\n", + "a10" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "36" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 47 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WDhy2BFOXQOb", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy 1d array consisting of five *random* integers between 1 and 50\n", + "\n", + "`array([36, 30, 32, 14, 2])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "tsljNldUXQOc", + "colab_type": "code", + "colab": {}, + "outputId": "14723c71-0b7d-4ab2-faf6-7fb291529576" + }, + "source": [ + "a11 = np.random.randint(1, 50, size=(5))\n", + "a11" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([41, 43, 23, 28, 14])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 48 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tZcYx6kVXQOg", + "colab_type": "text" + }, + "source": [ + "#### Create a Numpy array consisting of 20 linearly spaced points between 0 and 1\n", + "\n", + "`array([ 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. ])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "41ed4-0rXQOh", + "colab_type": "code", + "colab": {}, + "outputId": "7b3ad7ed-b2f0-4fbc-dd48-3af036bde2f8" + }, + "source": [ + "a12 = np.random.random(20)\n", + "a12" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0.35461186, 0.71027829, 0.51195462, 0.84389804, 0.51595563,\n", + " 0.41546301, 0.10441333, 0.46561315, 0.63735201, 0.16660066,\n", + " 0.11609039, 0.66684294, 0.44709994, 0.14481748, 0.39836158,\n", + " 0.04509681, 0.69683096, 0.10345124, 0.75850487, 0.25542027])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 53 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SmGanf3EXQOp", + "colab_type": "text" + }, + "source": [ + "#### Create the following Numpy 2d array:\n", + "\n", + "`array([[ 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. ]])`" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "srIwqxEgXQOq", + "colab_type": "code", + "colab": {}, + "outputId": "6ffc7798-9e50-4f61-e4a9-8c9af9459586" + }, + "source": [ + "a13 = np.arange(0.01, 1.01, 0.01).reshape(10, 10)\n", + "a13" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[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. ]])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 56 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LHQU5IEnXQOu", + "colab_type": "text" + }, + "source": [ + "-----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "id": "XURw5nAGXQOv", + "colab_type": "text" + }, + "source": [ + "# Great Job!" + ] + } + ] +} \ No newline at end of file