diff --git a/Questions/Excercise numpy .ipynb b/Questions/Excercise numpy .ipynb index 92ed880..9bae597 100644 --- a/Questions/Excercise numpy .ipynb +++ b/Questions/Excercise numpy .ipynb @@ -1 +1,288 @@ -{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Excercise numpy .ipynb","provenance":[],"authorship_tag":"ABX9TyMEuYnB4Fa7QF811lAB6GtK"},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"a_4UupTr9fbX","colab_type":"text"},"source":["# Numpy Exercises\n","\n","1) Create a uniform subdivision of the interval -1.3 to 2.5 with 64 subdivisions"]},{"cell_type":"code","metadata":{"id":"LIP5u4zi0Nmg","colab_type":"code","colab":{}},"source":["import numpy as np #import numpy"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"dBoH_A7M9jjL","colab_type":"text"},"source":["2) Generate an array of length 3n filled with the cyclic pattern 1, 2, 3"]},{"cell_type":"code","metadata":{"id":"4TxT66309n1o","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Vh-UKizx9oTp","colab_type":"text"},"source":["3) Create an array of the first 10 odd integers."]},{"cell_type":"code","metadata":{"id":"ebhEUZq29r32","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"QfJRdMat90f4","colab_type":"text"},"source":["4) Find intersection of a and b"]},{"cell_type":"code","metadata":{"id":"gOlfuJCo-JwF","colab_type":"code","colab":{}},"source":["#expected output array([2, 4])\n","a = np.array([1,2,3,2,3,4,3,4,5,6])\n","b = np.array([7,2,10,2,7,4,9,4,9,8])"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"RtVCf0UoCeB8","colab_type":"text"},"source":["5) Reshape 1d array a to 2d array of 2X5"]},{"cell_type":"code","metadata":{"id":"2E8b55_2Cjx5","colab_type":"code","colab":{}},"source":["a = np.arange(10)"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"dVrSBW1zEjp2","colab_type":"text"},"source":["6) Create a numpy array to list and vice versa"]},{"cell_type":"code","metadata":{"id":"tcBCyhXPEp9C","colab_type":"code","colab":{}},"source":["a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"JNqX8wnz9sQJ","colab_type":"text"},"source":["7) Create a 10 x 10 arrays of zeros and then \"frame\" it with a border of ones."]},{"cell_type":"code","metadata":{"id":"4bjP3JAc9vRD","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"xaQgf8tT9v-n","colab_type":"text"},"source":["8) Create an 8 x 8 array with a checkerboard pattern of zeros and ones using a slicing+striding approach."]},{"cell_type":"code","metadata":{"id":"No7fx0Xy9zEh","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]}]} \ No newline at end of file +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Excercise numpy .ipynb", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "a_4UupTr9fbX", + "colab_type": "text" + }, + "source": [ + "# Numpy Exercises\n", + "\n", + "1) Create a uniform subdivision of the interval -1.3 to 2.5 with 64 subdivisions" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "LIP5u4zi0Nmg", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import numpy as np #import numpy" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dBoH_A7M9jjL", + "colab_type": "text" + }, + "source": [ + "2) Generate an array of length 3n filled with the cyclic pattern 1, 2, 3" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "4TxT66309n1o", + "colab_type": "code", + "outputId": "d8400a1a-71a6-45f3-b3bb-01cc127c2a71", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "a= np.array([1,2,3])\n", + "print(a)" + ], + "execution_count": 12, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1 2 3]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Vh-UKizx9oTp", + "colab_type": "text" + }, + "source": [ + "3) Create an array of the first 10 odd integers." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ebhEUZq29r32", + "colab_type": "code", + "outputId": "8680bc2b-edd5-4d21-dc13-23f4f98b21d6", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "b=np.arange(1,20,2)\n", + "print(b)" + ], + "execution_count": 13, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[ 1 3 5 7 9 11 13 15 17 19]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "QfJRdMat90f4", + "colab_type": "text" + }, + "source": [ + "4) Find intersection of a and b" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "gOlfuJCo-JwF", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "f886865b-b263-457e-8b1d-d8d7a076b92f" + }, + "source": [ + "#expected output array([2, 4])\n", + "a = np.array([1,2,3,2,3,4,3,4,5,6])\n", + "b = np.array([7,2,10,2,7,4,9,4,9,8])\n", + "common=set(a) & set(b)\n", + "print(common)\n", + "\n" + ], + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "text": [ + "{2, 4}\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RtVCf0UoCeB8", + "colab_type": "text" + }, + "source": [ + "5) Reshape 1d array a to 2d array of 2X5" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "2E8b55_2Cjx5", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 52 + }, + "outputId": "efaac056-f8da-4838-cd93-52385c34f87d" + }, + "source": [ + "a = np.arange(10)\n", + "b=a.reshape(2,5)\n", + "print(b)" + ], + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[0 1 2 3 4]\n", + " [5 6 7 8 9]]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dVrSBW1zEjp2", + "colab_type": "text" + }, + "source": [ + "6) Create a numpy array to list and vice versa" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "tcBCyhXPEp9C", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 52 + }, + "outputId": "46afaf08-42cb-448e-d3a7-3b8705068d55" + }, + "source": [ + "a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + "b=np.array(a) #creating a array\n", + "print(b)\n", + "a=list(a) #creating a list\n", + "print(a)" + ], + "execution_count": 10, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1 2 3 4 5 6 7 8 9]\n", + "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JNqX8wnz9sQJ", + "colab_type": "text" + }, + "source": [ + "7) Create a 10 x 10 arrays of zeros and then \"frame\" it with a border of ones." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "4bjP3JAc9vRD", + "colab_type": "code", + "colab": {} + }, + "source": [ + "\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xaQgf8tT9v-n", + "colab_type": "text" + }, + "source": [ + "8) Create an 8 x 8 array with a checkerboard pattern of zeros and ones using a slicing+striding approach." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "No7fx0Xy9zEh", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Questions/List 1.ipynb b/Questions/List 1.ipynb index 144d52a..0421b49 100644 --- a/Questions/List 1.ipynb +++ b/Questions/List 1.ipynb @@ -1 +1,324 @@ -{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"List 1.ipynb","provenance":[],"authorship_tag":"ABX9TyNLahDgX6PyIABRXbqfMC/+"},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"e0R1W0Vzm4UU","colab_type":"text"},"source":["# Exercise - List"]},{"cell_type":"markdown","metadata":{"id":"TrO7XNQnnQZ7","colab_type":"text"},"source":["1) Create any random list and assign it to a variable dummy_list"]},{"cell_type":"code","metadata":{"id":"bjl-2QkznWid","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"cDjddNGfngnp","colab_type":"text"},"source":["2) print dummy_list"]},{"cell_type":"code","metadata":{"id":"RVL5178inz9M","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"15jKDXxkn16M","colab_type":"text"},"source":["3) Reverse dummy_list and print"]},{"cell_type":"code","metadata":{"id":"bYa9gFOOn-4o","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"EShv0nfXpUys","colab_type":"text"},"source":["4) Add the list dummy_list_2 to the previous dummy_list and now print dummy_list"]},{"cell_type":"code","metadata":{"id":"Ngkc7hnYphg6","colab_type":"code","colab":{}},"source":["dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Le1aRTuYoDzS","colab_type":"text"},"source":["5) Create a dictionary named dummy_dict which contains all the elements of dummy_list as keys and frequency as values. "]},{"cell_type":"code","metadata":{"id":"VHfSR_Csthnk","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"rtPC6WkSos-y","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"RgCYpFXGou6q","colab_type":"text"},"source":["6) print dummy_dict"]},{"cell_type":"code","metadata":{"id":"qe5E5IgxpTWU","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"8n_nsBDup4--","colab_type":"text"},"source":["7) Sort dummy_list in ascending order as well as descending order and print the changed lists "]},{"cell_type":"code","metadata":{"id":"Z_m7vr26qKnK","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Znm5Qo4LqPKA","colab_type":"text"},"source":["8) Remove the first item from the list whose value is equal to x. It raises a ValueError if there is no such item."]},{"cell_type":"code","metadata":{"id":"1-8mlngDqYvS","colab_type":"code","colab":{}},"source":["x = 200\n","\n","# Let's play: try the same with something which is not in the list to get the ValueError"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"QPB6iGbeqviN","colab_type":"text"},"source":["9) Remove the item at position x. x is any random integer"]},{"cell_type":"code","metadata":{"id":"aMyo1gmRrVHo","colab_type":"code","colab":{}},"source":["# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"bqQnnsr8rm6G","colab_type":"text"},"source":["10) Let's clean everything clear the list and then print"]},{"cell_type":"code","metadata":{"id":"qBC8lKpLrtJW","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]}]} \ No newline at end of file +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "List 1.ipynb", + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "e0R1W0Vzm4UU", + "colab_type": "text" + }, + "source": [ + "# Exercise - List" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TrO7XNQnnQZ7", + "colab_type": "text" + }, + "source": [ + "1) Create any random list and assign it to a variable dummy_list" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "bjl-2QkznWid", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "79083249-5fb2-4821-d6b5-eaaecf1d2f8b" + }, + "source": [ + "a=list([1,2,3,4,5,6,7,8,9])\n", + "print(a)\n", + "dummy_list=a" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cDjddNGfngnp", + "colab_type": "text" + }, + "source": [ + "2) print dummy_list" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "RVL5178inz9M", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "985fb36d-ab70-48cc-a835-e9cf0836cb5c" + }, + "source": [ + "print(dummy_list)" + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "15jKDXxkn16M", + "colab_type": "text" + }, + "source": [ + "3) Reverse dummy_list and print" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "bYa9gFOOn-4o", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "1137d728-f5aa-42a0-b0d4-1ac928029172" + }, + "source": [ + "rev= dummy_list[::-1]\n", + "print(rev)" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[9, 8, 7, 6, 5, 4, 3, 2, 1]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EShv0nfXpUys", + "colab_type": "text" + }, + "source": [ + "4) Add the list dummy_list_2 to the previous dummy_list and now print dummy_list" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Ngkc7hnYphg6", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "995f9663-6f5c-48b1-b1f4-8ec54800f8dc" + }, + "source": [ + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "merge= rev + dummy_list_2\n", + "print(merge)" + ], + "execution_count": 14, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Le1aRTuYoDzS", + "colab_type": "text" + }, + "source": [ + "5) Create a dictionary named dummy_dict which contains all the elements of dummy_list as keys and frequency as values. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "VHfSR_Csthnk", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "rtPC6WkSos-y", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RgCYpFXGou6q", + "colab_type": "text" + }, + "source": [ + "6) print dummy_dict" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "qe5E5IgxpTWU", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "8n_nsBDup4--", + "colab_type": "text" + }, + "source": [ + "7) Sort dummy_list in ascending order as well as descending order and print the changed lists " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Z_m7vr26qKnK", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Znm5Qo4LqPKA", + "colab_type": "text" + }, + "source": [ + "8) Remove the first item from the list whose value is equal to x. It raises a ValueError if there is no such item." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "1-8mlngDqYvS", + "colab_type": "code", + "colab": {} + }, + "source": [ + "x = 200\n", + "\n", + "# Let's play: try the same with something which is not in the list to get the ValueError" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "QPB6iGbeqviN", + "colab_type": "text" + }, + "source": [ + "9) Remove the item at position x. x is any random integer" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "aMyo1gmRrVHo", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "bqQnnsr8rm6G", + "colab_type": "text" + }, + "source": [ + "10) Let's clean everything clear the list and then print" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "qBC8lKpLrtJW", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file