From acbe4fecf1b988b5151dc137b145e9801cdb42c1 Mon Sep 17 00:00:00 2001 From: Rohit Kumar Singh Date: Thu, 24 Sep 2020 19:40:04 +0530 Subject: [PATCH 1/5] Rohit-2020-09-24 --- Rohit-2020-09-24.ipynb | 816 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 816 insertions(+) create mode 100644 Rohit-2020-09-24.ipynb diff --git a/Rohit-2020-09-24.ipynb b/Rohit-2020-09-24.ipynb new file mode 100644 index 0000000..cdcd053 --- /dev/null +++ b/Rohit-2020-09-24.ipynb @@ -0,0 +1,816 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# GRAY INTERFACE \n", + "\n", + "## HackSlash " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# NumPy" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 1: Creating Numpy arrays" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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": {}, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Import numpy" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create Numpy arrays from Python list\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Create Numpy 1d array from list\n", + "\n", + "`array([1, 2, 3])`" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "list_1d = np.array[1,2,3]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list_1d" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Create Numpy 2d array from list\n", + "\n", + "`array([[1, 2, 3],\n", + " [4, 5, 6]])`" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "list_2d = np.array([[1,2,3],\n", + " [4,5,6]])" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1, 2, 3],\n", + " [4, 5, 6]])" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list_2d" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Create Numpy 3d array from list" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`array([[[1, 2, 3],\n", + " [4, 5, 6]],\n", + " [[1, 2, 3],\n", + " [4, 5, 6]]])`" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "list_3d = np.array([[[1,2,3],\n", + " [4,5,6]], \n", + " [[1,2,3],\n", + " [4,5,6]]])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[1, 2, 3],\n", + " [4, 5, 6]],\n", + "\n", + " [[1, 2, 3],\n", + " [4, 5, 6]]])" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list_3d" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create Numpy arrays using functions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "zeros = np.zeros(10)\n", + "zeros" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 10, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ones = np.ones(10)\n", + "ones" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([5, 5, 5, 5, 5, 5, 5, 5, 5, 5])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fives = ones*5\n", + "fives.astype(int)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "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])" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a1 = np.arange(10, 50)\n", + "a1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "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])" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a2 = np.arange(10, 50, 2)\n", + "a2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1., 1., 1.],\n", + " [1., 1., 1.],\n", + " [1., 1., 1.]])" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a3 = np.ones((3,3))\n", + "a3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "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.]])" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a4 = np.zeros((10, 10))\n", + "np.fill_diagonal(a4, 1)\n", + "a4" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "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]])" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a5 = np.arange(1, 31).reshape(5, 6)\n", + "a5" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Create a Numpy 1d array consisting of a random number between 0 and 1\n", + "\n", + "`array([0.42829726])`" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0.07729339])" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a6 = np.random.random(1)\n", + "a6" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0.31603255, 0.94442351, 0.67546733, 0.49993517, 0.12707087,\n", + " 0.49862089])" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a7 = np.random.random(6)\n", + "a7" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0.39039111, 0.82852577, 0.76315103],\n", + " [0.82700325, 0.08247063, 0.13188691]])" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a8 = np.random.random(size=(2, 3))\n", + "a8" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "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])" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a9 = np.random.normal(0, 1, 25)\n", + "a9" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Generate a *random* integer between 1 and 50\n", + "\n", + "`32`" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "36" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a10 = np.random.randint(1, 50)\n", + "a10" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([41, 43, 23, 28, 14])" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a11 = np.random.randint(1, 50, size=(5))\n", + "a11" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "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])" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a12 = np.random.random(20)\n", + "a12" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "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. ]])" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a13 = np.arange(0.01, 1.01, 0.01).reshape(10, 10)\n", + "a13" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Great Job!" + ] + } + ], + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} From 9f8cd6af0a0f06fa8e24d997742c871bff169788 Mon Sep 17 00:00:00 2001 From: Rohit Kumar Singh <55323686+voidrohit@users.noreply.github.com> Date: Fri, 25 Sep 2020 19:18:20 +0530 Subject: [PATCH 2/5] Created using Colaboratory --- Rohit-2020-09-24.ipynb | 1874 +++++++++++++++++++++++----------------- 1 file changed, 1062 insertions(+), 812 deletions(-) diff --git a/Rohit-2020-09-24.ipynb b/Rohit-2020-09-24.ipynb index cdcd053..48f50d4 100644 --- a/Rohit-2020-09-24.ipynb +++ b/Rohit-2020-09-24.ipynb @@ -1,816 +1,1066 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# GRAY INTERFACE \n", - "\n", - "## HackSlash " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "----" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# NumPy" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Exercise 1: Creating Numpy arrays" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "----" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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": {}, - "source": [ - "----" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Import numpy" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create Numpy arrays from Python list\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Create Numpy 1d array from list\n", - "\n", - "`array([1, 2, 3])`" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "list_1d = np.array[1,2,3]" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 3]" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "list_1d" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Create Numpy 2d array from list\n", - "\n", - "`array([[1, 2, 3],\n", - " [4, 5, 6]])`" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "list_2d = np.array([[1,2,3],\n", - " [4,5,6]])" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[1, 2, 3],\n", - " [4, 5, 6]])" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "list_2d" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Create Numpy 3d array from list" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`array([[[1, 2, 3],\n", - " [4, 5, 6]],\n", - " [[1, 2, 3],\n", - " [4, 5, 6]]])`" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "list_3d = np.array([[[1,2,3],\n", - " [4,5,6]], \n", - " [[1,2,3],\n", - " [4,5,6]]])" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[[1, 2, 3],\n", - " [4, 5, 6]],\n", - "\n", - " [[1, 2, 3],\n", - " [4, 5, 6]]])" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "list_3d" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "-----" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create Numpy arrays using functions" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "zeros = np.zeros(10)\n", - "zeros" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 10, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ones = np.ones(10)\n", - "ones" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([5, 5, 5, 5, 5, 5, 5, 5, 5, 5])" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "fives = ones*5\n", - "fives.astype(int)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "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])" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a1 = np.arange(10, 50)\n", - "a1" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "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])" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a2 = np.arange(10, 50, 2)\n", - "a2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[1., 1., 1.],\n", - " [1., 1., 1.],\n", - " [1., 1., 1.]])" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a3 = np.ones((3,3))\n", - "a3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "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.]])" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a4 = np.zeros((10, 10))\n", - "np.fill_diagonal(a4, 1)\n", - "a4" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 37, - "metadata": {}, - "outputs": [ - { - "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]])" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a5 = np.arange(1, 31).reshape(5, 6)\n", - "a5" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Create a Numpy 1d array consisting of a random number between 0 and 1\n", - "\n", - "`array([0.42829726])`" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([0.07729339])" - ] - }, - "execution_count": 41, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a6 = np.random.random(1)\n", - "a6" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 40, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([0.31603255, 0.94442351, 0.67546733, 0.49993517, 0.12707087,\n", - " 0.49862089])" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a7 = np.random.random(6)\n", - "a7" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 43, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[0.39039111, 0.82852577, 0.76315103],\n", - " [0.82700325, 0.08247063, 0.13188691]])" - ] - }, - "execution_count": 43, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a8 = np.random.random(size=(2, 3))\n", - "a8" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 45, - "metadata": {}, - "outputs": [ - { - "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])" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a9 = np.random.normal(0, 1, 25)\n", - "a9" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Generate a *random* integer between 1 and 50\n", - "\n", - "`32`" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "36" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a10 = np.random.randint(1, 50)\n", - "a10" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 48, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([41, 43, 23, 28, 14])" - ] - }, - "execution_count": 48, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a11 = np.random.randint(1, 50, size=(5))\n", - "a11" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 53, - "metadata": {}, - "outputs": [ - { - "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])" - ] - }, - "execution_count": 53, - "metadata": {}, - "output_type": "execute_result" + "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": [] } - ], - "source": [ - "a12 = np.random.random(20)\n", - "a12" - ] }, - { - "cell_type": "markdown", - "metadata": {}, - "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", - "execution_count": 56, - "metadata": {}, - "outputs": [ - { - "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. ]])" - ] - }, - "execution_count": 56, - "metadata": {}, - "output_type": "execute_result" + "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!" + ] } - ], - "source": [ - "a13 = np.arange(0.01, 1.01, 0.01).reshape(10, 10)\n", - "a13" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "-----" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "# Great Job!" - ] - } - ], - "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" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + ] +} \ No newline at end of file From dcbb0207b65b9320b00b21f0dff250cf208c4588 Mon Sep 17 00:00:00 2001 From: Rohit Kumar Singh <55323686+voidrohit@users.noreply.github.com> Date: Fri, 25 Sep 2020 19:30:16 +0530 Subject: [PATCH 3/5] Created using Colaboratory --- Rohit_assignment_1.ipynb | 1066 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 1066 insertions(+) create mode 100644 Rohit_assignment_1.ipynb 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 From 226bb7b379369b1a87a16427b6e86502307c1156 Mon Sep 17 00:00:00 2001 From: Paritosh Kumar Date: Fri, 25 Sep 2020 20:42:33 +0530 Subject: [PATCH 4/5] Modified Markdown cells at the top Omitted tag from three cells --- Rohit-2020-09-24.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Rohit-2020-09-24.ipynb b/Rohit-2020-09-24.ipynb index 48f50d4..7c38498 100644 --- a/Rohit-2020-09-24.ipynb +++ b/Rohit-2020-09-24.ipynb @@ -32,9 +32,9 @@ "colab_type": "text" }, "source": [ - "# GRAY INTERFACE \n", + "# GRAY INTERFACE \n", "\n", - "## HackSlash " + "## HackSlash " ] }, { @@ -54,7 +54,7 @@ "colab_type": "text" }, "source": [ - "# NumPy" + "# NumPy" ] }, { @@ -1063,4 +1063,4 @@ ] } ] -} \ No newline at end of file +} From 91d300a0925ad60221796da5878b822b5b530563 Mon Sep 17 00:00:00 2001 From: Rohit Kumar Singh <55323686+voidrohit@users.noreply.github.com> Date: Fri, 25 Sep 2020 23:01:07 +0530 Subject: [PATCH 5/5] Created using Colaboratory --- Rohit-2020-09-24.ipynb | 177 ++++++++++++----------------------------- 1 file changed, 51 insertions(+), 126 deletions(-) diff --git a/Rohit-2020-09-24.ipynb b/Rohit-2020-09-24.ipynb index 7c38498..114534d 100644 --- a/Rohit-2020-09-24.ipynb +++ b/Rohit-2020-09-24.ipynb @@ -28,8 +28,7 @@ { "cell_type": "markdown", "metadata": { - "id": "ysZ_Zc7jXQLm", - "colab_type": "text" + "id": "ysZ_Zc7jXQLm" }, "source": [ "# GRAY INTERFACE \n", @@ -40,8 +39,7 @@ { "cell_type": "markdown", "metadata": { - "id": "SeiOUaMLXQLo", - "colab_type": "text" + "id": "SeiOUaMLXQLo" }, "source": [ "----" @@ -50,8 +48,7 @@ { "cell_type": "markdown", "metadata": { - "id": "0VcY6iWPXQLu", - "colab_type": "text" + "id": "0VcY6iWPXQLu" }, "source": [ "# NumPy" @@ -60,8 +57,7 @@ { "cell_type": "markdown", "metadata": { - "id": "sveBt_S5XQLv", - "colab_type": "text" + "id": "sveBt_S5XQLv" }, "source": [ "## Exercise 1: Creating Numpy arrays" @@ -70,8 +66,7 @@ { "cell_type": "markdown", "metadata": { - "id": "fnIyQKKoXQLx", - "colab_type": "text" + "id": "fnIyQKKoXQLx" }, "source": [ "----" @@ -80,8 +75,7 @@ { "cell_type": "markdown", "metadata": { - "id": "FKz52UNSXQLy", - "colab_type": "text" + "id": "FKz52UNSXQLy" }, "source": [ "#### Write & Run CODE to answer each of the given problem statement.\n", @@ -91,8 +85,7 @@ { "cell_type": "markdown", "metadata": { - "id": "UPzeXKd-XQL0", - "colab_type": "text" + "id": "UPzeXKd-XQL0" }, "source": [ "----" @@ -101,8 +94,7 @@ { "cell_type": "markdown", "metadata": { - "id": "JR3ziOY4XQL1", - "colab_type": "text" + "id": "JR3ziOY4XQL1" }, "source": [ "## Import numpy" @@ -111,21 +103,18 @@ { "cell_type": "code", "metadata": { - "id": "xorAeajEXQL3", - "colab_type": "code", - "colab": {} + "id": "xorAeajEXQL3" }, "source": [ "import numpy as np" ], - "execution_count": null, + "execution_count": 2, "outputs": [] }, { "cell_type": "markdown", "metadata": { - "id": "_9FTYkoYXQL_", - "colab_type": "text" + "id": "_9FTYkoYXQL_" }, "source": [ "## Create Numpy arrays from Python list\n" @@ -134,8 +123,7 @@ { "cell_type": "markdown", "metadata": { - "id": "v9ebkdjTXQMB", - "colab_type": "text" + "id": "v9ebkdjTXQMB" }, "source": [ "#### Create Numpy 1d array from list\n", @@ -146,9 +134,7 @@ { "cell_type": "code", "metadata": { - "id": "uxR42QFrXQMC", - "colab_type": "code", - "colab": {} + "id": "uxR42QFrXQMC" }, "source": [ "list_1d = np.array[1,2,3]" @@ -160,8 +146,6 @@ "cell_type": "code", "metadata": { "id": "jnwKmdKIXQMI", - "colab_type": "code", - "colab": {}, "outputId": "c760bd50-451c-444c-b4c1-45c2344b799f" }, "source": [ @@ -186,8 +170,7 @@ { "cell_type": "markdown", "metadata": { - "id": "Nku-ubYJXQMR", - "colab_type": "text" + "id": "Nku-ubYJXQMR" }, "source": [ "#### Create Numpy 2d array from list\n", @@ -199,9 +182,7 @@ { "cell_type": "code", "metadata": { - "id": "kNVCtO9aXQMT", - "colab_type": "code", - "colab": {} + "id": "kNVCtO9aXQMT" }, "source": [ "list_2d = np.array([[1,2,3],\n", @@ -214,8 +195,6 @@ "cell_type": "code", "metadata": { "id": "07BN26LPXQMY", - "colab_type": "code", - "colab": {}, "outputId": "fd475be6-6b2c-47c6-b321-7f4266b2b941" }, "source": [ @@ -241,8 +220,7 @@ { "cell_type": "markdown", "metadata": { - "id": "5dKPATOKXQMg", - "colab_type": "text" + "id": "5dKPATOKXQMg" }, "source": [ "#### Create Numpy 3d array from list" @@ -251,8 +229,7 @@ { "cell_type": "markdown", "metadata": { - "id": "GMOEEx7eXQMi", - "colab_type": "text" + "id": "GMOEEx7eXQMi" }, "source": [ "`array([[[1, 2, 3],\n", @@ -264,9 +241,7 @@ { "cell_type": "code", "metadata": { - "id": "PrcKqmOkXQMj", - "colab_type": "code", - "colab": {} + "id": "PrcKqmOkXQMj" }, "source": [ "list_3d = np.array([[[1,2,3],\n", @@ -281,8 +256,6 @@ "cell_type": "code", "metadata": { "id": "OT3ILqxOXQMq", - "colab_type": "code", - "colab": {}, "outputId": "25f5fcdf-a5e9-472f-a570-dc7a9eea2a4a" }, "source": [ @@ -311,8 +284,7 @@ { "cell_type": "markdown", "metadata": { - "id": "Ic_ihn5RXQMy", - "colab_type": "text" + "id": "Ic_ihn5RXQMy" }, "source": [ "-----" @@ -321,8 +293,7 @@ { "cell_type": "markdown", "metadata": { - "id": "3nK7dFFSXQMz", - "colab_type": "text" + "id": "3nK7dFFSXQMz" }, "source": [ "## Create Numpy arrays using functions" @@ -331,8 +302,7 @@ { "cell_type": "markdown", "metadata": { - "id": "cZiD_nJqXQM1", - "colab_type": "text" + "id": "cZiD_nJqXQM1" }, "source": [ "#### Create a Numpy 1d array of 10 zeros \n", @@ -344,8 +314,6 @@ "cell_type": "code", "metadata": { "id": "VNejzKqOXQM2", - "colab_type": "code", - "colab": {}, "outputId": "c594ed73-c97e-4702-cf26-2861c234378c" }, "source": [ @@ -371,8 +339,7 @@ { "cell_type": "markdown", "metadata": { - "id": "2AQwry-EXQM9", - "colab_type": "text" + "id": "2AQwry-EXQM9" }, "source": [ "#### Create a Numpy 1d array of 10 ones\n", @@ -385,8 +352,6 @@ "metadata": { "scrolled": true, "id": "DI1iHZ1MXQNB", - "colab_type": "code", - "colab": {}, "outputId": "4862d3f1-3eca-403a-e514-88034aab76a3" }, "source": [ @@ -412,8 +377,7 @@ { "cell_type": "markdown", "metadata": { - "id": "F0DmLwW6XQNJ", - "colab_type": "text" + "id": "F0DmLwW6XQNJ" }, "source": [ "#### Create a Numpy 1d array of 10 fives\n", @@ -425,8 +389,6 @@ "cell_type": "code", "metadata": { "id": "2jEuCWsnXQNL", - "colab_type": "code", - "colab": {}, "outputId": "151f8cb2-f5e5-4067-fde6-1e7fffd8125b" }, "source": [ @@ -452,8 +414,7 @@ { "cell_type": "markdown", "metadata": { - "id": "e7Im8l-SXQNR", - "colab_type": "text" + "id": "e7Im8l-SXQNR" }, "source": [ "#### Create a Numpy 1d array consisting of all the integers from 10 to 50\n", @@ -467,8 +428,6 @@ "cell_type": "code", "metadata": { "id": "F4P_lpCpXQNT", - "colab_type": "code", - "colab": {}, "outputId": "30d7f654-a3e4-45a4-e687-ceffd49a1dc2" }, "source": [ @@ -496,8 +455,7 @@ { "cell_type": "markdown", "metadata": { - "id": "S8xN5LSmXQNZ", - "colab_type": "text" + "id": "S8xN5LSmXQNZ" }, "source": [ "#### Create a Numpy 1d array consisting of all the even integers only from 10 to 50\n", @@ -510,8 +468,6 @@ "cell_type": "code", "metadata": { "id": "nvFKpXqlXQNb", - "colab_type": "code", - "colab": {}, "outputId": "f23b9d3b-f3ea-4cb1-a82a-d1cf3f68f31f" }, "source": [ @@ -538,8 +494,7 @@ { "cell_type": "markdown", "metadata": { - "id": "C1Ljd4C7XQNj", - "colab_type": "text" + "id": "C1Ljd4C7XQNj" }, "source": [ "#### Create a Numpy 2d array with shape (3,3) having all entries as 1\n", @@ -553,8 +508,6 @@ "cell_type": "code", "metadata": { "id": "PJ4tous6XQNk", - "colab_type": "code", - "colab": {}, "outputId": "2dd9f0db-a315-435a-8b97-a0950a5fa5eb" }, "source": [ @@ -582,8 +535,7 @@ { "cell_type": "markdown", "metadata": { - "id": "LzW6gWxRXQNp", - "colab_type": "text" + "id": "LzW6gWxRXQNp" }, "source": [ "#### Create a Numpy 2d array with shape (10,10) having all diagonal entries as 1 and all others as 0\n", @@ -604,8 +556,6 @@ "cell_type": "code", "metadata": { "id": "Jktw1-IuXQNq", - "colab_type": "code", - "colab": {}, "outputId": "8124bf1d-e304-4a2d-ff4e-60219e7ddf5e" }, "source": [ @@ -641,8 +591,7 @@ { "cell_type": "markdown", "metadata": { - "id": "LPRJ-r8oXQNv", - "colab_type": "text" + "id": "LPRJ-r8oXQNv" }, "source": [ "#### Create a Numpy 2d array with shape (5,6) consisting of values ranging from 1 to 30\n", @@ -658,8 +607,6 @@ "cell_type": "code", "metadata": { "id": "0wbQZ01ZXQNw", - "colab_type": "code", - "colab": {}, "outputId": "cd67b846-132a-45ef-f155-e579a0fd4563" }, "source": [ @@ -689,8 +636,7 @@ { "cell_type": "markdown", "metadata": { - "id": "cfqhkD61XQN1", - "colab_type": "text" + "id": "cfqhkD61XQN1" }, "source": [ "#### Create a Numpy 1d array consisting of a random number between 0 and 1\n", @@ -702,8 +648,6 @@ "cell_type": "code", "metadata": { "id": "F69msW1lXQN2", - "colab_type": "code", - "colab": {}, "outputId": "501ee287-a66f-4885-c307-e3d00a3cf676" }, "source": [ @@ -729,8 +673,7 @@ { "cell_type": "markdown", "metadata": { - "id": "TMRKw8DSXQN7", - "colab_type": "text" + "id": "TMRKw8DSXQN7" }, "source": [ "#### Create a Numpy 1d array consisting of six *random* numbers between 0 and 1\n", @@ -742,8 +685,6 @@ "cell_type": "code", "metadata": { "id": "gF-6VJb3XQN9", - "colab_type": "code", - "colab": {}, "outputId": "08b401f2-4fe4-4baa-f710-96f2b47540ea" }, "source": [ @@ -770,8 +711,7 @@ { "cell_type": "markdown", "metadata": { - "id": "tXPgOjFmXQOD", - "colab_type": "text" + "id": "tXPgOjFmXQOD" }, "source": [ "#### Create a Numpy 2d array of shape (2,3) consisting of five *random* numbers between 0 and 1\n", @@ -784,8 +724,6 @@ "cell_type": "code", "metadata": { "id": "hfaVKpSfXQOF", - "colab_type": "code", - "colab": {}, "outputId": "807fa887-49af-43ec-fbdb-64c02a422a38" }, "source": [ @@ -812,8 +750,7 @@ { "cell_type": "markdown", "metadata": { - "id": "Cf6WLC80XQOK", - "colab_type": "text" + "id": "Cf6WLC80XQOK" }, "source": [ "#### Create a Numpy 1d array consisting of 25 random numbers sampled from a *Standard Normal Distribution*\n", @@ -829,8 +766,6 @@ "cell_type": "code", "metadata": { "id": "8O_rJstOXQOL", - "colab_type": "code", - "colab": {}, "outputId": "9822152c-5351-4e72-b43f-31d181e4dc4a" }, "source": [ @@ -860,8 +795,7 @@ { "cell_type": "markdown", "metadata": { - "id": "ANYwg3TgXQOQ", - "colab_type": "text" + "id": "ANYwg3TgXQOQ" }, "source": [ "#### Generate a *random* integer between 1 and 50\n", @@ -873,8 +807,6 @@ "cell_type": "code", "metadata": { "id": "_5zQOBImXQOT", - "colab_type": "code", - "colab": {}, "outputId": "aaf7a36f-a343-4f92-ede7-30f73735f6b9" }, "source": [ @@ -900,8 +832,7 @@ { "cell_type": "markdown", "metadata": { - "id": "WDhy2BFOXQOb", - "colab_type": "text" + "id": "WDhy2BFOXQOb" }, "source": [ "#### Create a Numpy 1d array consisting of five *random* integers between 1 and 50\n", @@ -913,8 +844,6 @@ "cell_type": "code", "metadata": { "id": "tsljNldUXQOc", - "colab_type": "code", - "colab": {}, "outputId": "14723c71-0b7d-4ab2-faf6-7fb291529576" }, "source": [ @@ -940,8 +869,7 @@ { "cell_type": "markdown", "metadata": { - "id": "tZcYx6kVXQOg", - "colab_type": "text" + "id": "tZcYx6kVXQOg" }, "source": [ "#### Create a Numpy array consisting of 20 linearly spaced points between 0 and 1\n", @@ -956,38 +884,39 @@ "cell_type": "code", "metadata": { "id": "41ed4-0rXQOh", - "colab_type": "code", - "colab": {}, - "outputId": "7b3ad7ed-b2f0-4fbc-dd48-3af036bde2f8" + "outputId": "bf01dd86-ebc5-440e-ad0d-05bdb0c6c5e1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 87 + } }, "source": [ - "a12 = np.random.random(20)\n", + "a12 = np.linspace(0, 1, num=20)\n", "a12" ], - "execution_count": null, + "execution_count": 3, "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])" + "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": 53 + "execution_count": 3 } ] }, { "cell_type": "markdown", "metadata": { - "id": "SmGanf3EXQOp", - "colab_type": "text" + "id": "SmGanf3EXQOp" }, "source": [ "#### Create the following Numpy 2d array:\n", @@ -1008,8 +937,6 @@ "cell_type": "code", "metadata": { "id": "srIwqxEgXQOq", - "colab_type": "code", - "colab": {}, "outputId": "6ffc7798-9e50-4f61-e4a9-8c9af9459586" }, "source": [ @@ -1044,8 +971,7 @@ { "cell_type": "markdown", "metadata": { - "id": "LHQU5IEnXQOu", - "colab_type": "text" + "id": "LHQU5IEnXQOu" }, "source": [ "-----" @@ -1055,12 +981,11 @@ "cell_type": "markdown", "metadata": { "collapsed": true, - "id": "XURw5nAGXQOv", - "colab_type": "text" + "id": "XURw5nAGXQOv" }, "source": [ "# Great Job!" ] } ] -} +} \ No newline at end of file