From bb40cbf77da120c7d4542ea45037ce917eae57f2 Mon Sep 17 00:00:00 2001 From: Sayan46 <43204942+Sayan46@users.noreply.github.com> Date: Sun, 30 Sep 2018 22:52:48 +0530 Subject: [PATCH 1/3] Problem Solved --- Sayan46.ipynb | 293 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 263 insertions(+), 30 deletions(-) diff --git a/Sayan46.ipynb b/Sayan46.ipynb index 9e2543a..bfe33a1 100644 --- a/Sayan46.ipynb +++ b/Sayan46.ipynb @@ -1,32 +1,265 @@ { - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Sayan46.ipynb", + "version": "0.3.2", + "provenance": [] + }, + "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.5.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + "cells": [ + { + "metadata": { + "id": "Qe-ZxpUvSb2t", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "l1=[1,3,5,7,9,8,400,87,93,10]\n", + "dummy_list=l1[:]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "42Yq3oVuSkcU", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "d1390096-158b-4fa9-eba7-0d1bd0e0df99" + }, + "cell_type": "code", + "source": [ + "print(dummy_list)" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 3, 5, 7, 9, 8, 400, 87, 93, 10]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "I084a3G7TMOS", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "a420aa6c-a023-476a-a614-2dc8ddac3fbc" + }, + "cell_type": "code", + "source": [ + "dummy_list.reverse()\n", + "print(dummy_list)" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[10, 93, 87, 400, 8, 9, 7, 5, 3, 1]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "gP3_OHpFTt76", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "c1a288ed-d6be-46ef-d983-0a51fa378dcd" + }, + "cell_type": "code", + "source": [ + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "i = len(l1)\n", + "i1=0\n", + "p=len(dummy_list_2)\n", + "while i1 is not p:\n", + " dummy_list.insert(i+i1,dummy_list_2[i1])\n", + " i1 += 1\n", + "print(dummy_list)" + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[10, 93, 87, 400, 8, 9, 7, 5, 3, 1, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "s0Rt59pvUPov", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_dict={}\n", + "(i,j,c)=(0,0,0)\n", + "for i in range(len(dummy_list)):\n", + " for j in range(len(dummy_list)):\n", + " if(dummy_list[j]==dummy_list[i]):\n", + " c=c+1\n", + " dummy_dict[dummy_list[i]]=c\n", + " c=0" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "p8Aa_x26Wjsi", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "dd8ad13c-e5b7-47f4-e0f3-de019cce5f4d" + }, + "cell_type": "code", + "source": [ + "print(dummy_dict)" + ], + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "text": [ + "{10: 1, 93: 1, 87: 1, 400: 1, 8: 1, 9: 1, 7: 1, 5: 1, 3: 1, 1: 2, 2: 1, 200: 1, 16: 1, 4: 1, 0: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "Vw0FfvmeWnOR", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 50 + }, + "outputId": "483b1d92-c4d6-4f98-be7f-65cf238fbd96" + }, + "cell_type": "code", + "source": [ + "dummy_list.sort()\n", + "print(dummy_list)\n", + "dummy_list.sort(reverse=True)\n", + "print(dummy_list)" + ], + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0, 1, 1, 2, 3, 4, 5, 7, 8, 9, 9.45, 10, 12.01, 12.02, 16, 45.67, 87, 90, 93, 200, 400]\n", + "[400, 200, 93, 90, 87, 45.67, 16, 12.02, 12.01, 10, 9.45, 9, 8, 7, 5, 4, 3, 2, 1, 1, 0]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "ZhyQieKHj3lL", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "d3d7267b-9023-443c-935d-a5ee95ba82d1" + }, + "cell_type": "code", + "source": [ + "(x,f,a)=(200,0,0)\n", + "for a in range(len(dummy_list)):\n", + " if(dummy_list[a]==x):\n", + " f=1\n", + " dummy_list.remove(x)\n", + " break\n", + "if f==0:\n", + " print(\"No such integer is present in the list! Please try again ...\")\n" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "stream", + "text": [ + "No such integer is present in the list! Please try again ...\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "hZGSnQOOa8nn", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "x=10\n", + "del dummy_list[x]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "p7366u_YbDD9", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "a2fe3eec-f50b-4d63-fb56-48d24f689541" + }, + "cell_type": "code", + "source": [ + "i=len(dummy_list)\n", + "while i is not 0:\n", + " del dummy_list[i-1]\n", + " i-=1\n", + "print(dummy_list)\n", + "\n" + ], + "execution_count": 13, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[]\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From c4f267b367909499024eee64324fc31714045d2d Mon Sep 17 00:00:00 2001 From: Sayan46 <43204942+Sayan46@users.noreply.github.com> Date: Thu, 4 Oct 2018 21:26:49 +0530 Subject: [PATCH 2/3] Created using Colaboratory --- Numpy_Exercises.ipynb | 358 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 358 insertions(+) create mode 100644 Numpy_Exercises.ipynb diff --git a/Numpy_Exercises.ipynb b/Numpy_Exercises.ipynb new file mode 100644 index 0000000..ac41198 --- /dev/null +++ b/Numpy_Exercises.ipynb @@ -0,0 +1,358 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Numpy_Exercises.ipynb", + "version": "0.3.2", + "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": [ + "[View in Colaboratory](https://colab.research.google.com/github/Sayan46/Assignment-2/blob/Sayan46/Numpy_Exercises.ipynb)" + ] + }, + { + "metadata": { + "id": "a_4UupTr9fbX", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# Numpy Exercises\n", + "\n", + "1) Create a uniform subdivision of the interval -1.3 to 2.5 with 64 subdivisions" + ] + }, + { + "metadata": { + "id": "LIP5u4zi0Nmg", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 202 + }, + "outputId": "34d9f53c-d444-4c2b-8d79-72fffde0b0c5" + }, + "cell_type": "code", + "source": [ + "import numpy as np \n", + "s = np.random.uniform(-1.3,2.5,64)\n", + "print(s)\n" + ], + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[ 1.29714042 0.05382672 2.11603915 0.46257789 0.39152661 -0.14922545\n", + " 1.6112405 1.97758278 -1.23275156 -0.43644515 -0.83081985 -0.20409018\n", + " 0.9461046 -1.21474827 1.0501915 -0.65469646 0.21974205 2.0357349\n", + " -0.0210625 0.2303843 0.03695057 -0.22360614 1.57105111 0.44567277\n", + " -0.31814993 -0.33186138 1.83457452 0.64501397 -0.72027239 0.31311365\n", + " 2.22288395 -0.43783351 -0.5531905 -0.11004932 0.04434198 1.6141596\n", + " 1.29484714 -0.88055521 0.90784743 2.24186256 0.6197379 1.82008514\n", + " 2.14463852 2.4116079 0.80386049 -0.43050777 1.02151095 0.89904801\n", + " 1.44200865 0.00406608 1.20474749 1.03238049 -0.79745927 0.13132264\n", + " -0.04273136 -0.11766145 -0.8821126 1.15447771 2.12783845 0.59703821\n", + " 0.49830412 0.71234306 1.27832384 1.6935996 ]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "dBoH_A7M9jjL", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "2) Generate an array of length 3n filled with the cyclic pattern 1, 2, 3" + ] + }, + { + "metadata": { + "id": "4TxT66309n1o", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "a6353d5f-0b60-4b22-ba90-b6de1e10f3e7" + }, + "cell_type": "code", + "source": [ + "n=3\n", + "x = np.array([1,2,3])\n", + "y = np.tile(x,n)\n", + "print(y)" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1 2 3 1 2 3 1 2 3]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "Vh-UKizx9oTp", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "3) Create an array of the first 10 odd integers." + ] + }, + { + "metadata": { + "id": "ebhEUZq29r32", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "70fa21ec-cae3-44b7-8e78-188cfeab4d26" + }, + "cell_type": "code", + "source": [ + "a=np.array([1,3,5,7,9,11,13,15,17,19])\n", + "print(a)" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[ 1 3 5 7 9 11 13 15 17 19]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "QfJRdMat90f4", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "4) Find intersection of a and b" + ] + }, + { + "metadata": { + "id": "gOlfuJCo-JwF", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "cdcdcdd1-c262-4b6b-dc33-1c3122db770d" + }, + "cell_type": "code", + "source": [ + "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", + "print(np.intersect1d(a,b))" + ], + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[2 4]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "RtVCf0UoCeB8", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "5) Reshape 1d array a to 2d array of 2X5" + ] + }, + { + "metadata": { + "id": "2E8b55_2Cjx5", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 50 + }, + "outputId": "24cfe21c-9147-4e8c-f483-a8072e2c8639" + }, + "cell_type": "code", + "source": [ + "new = np.reshape(a,(2,5))\n", + "print(new)" + ], + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[1 2 3 2 3]\n", + " [4 3 4 5 6]]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "dVrSBW1zEjp2", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "6) Create a numpy array to list and vice versa" + ] + }, + { + "metadata": { + "id": "tcBCyhXPEp9C", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 50 + }, + "outputId": "2e74837a-614f-48f2-c4d3-2bfe25987616" + }, + "cell_type": "code", + "source": [ + "a=np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])\n", + "b=(a.tolist())\n", + "print(b)\n", + "a1=np.asarray(b)\n", + "print(a1)" + ], + "execution_count": 12, + "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" + } + ] + }, + { + "metadata": { + "id": "JNqX8wnz9sQJ", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "7) Create a 10 x 10 arrays of zeros and then \"frame\" it with a border of ones." + ] + }, + { + "metadata": { + "id": "4bjP3JAc9vRD", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 202 + }, + "outputId": "b0ea4aff-611c-4b15-82ff-6e66ae445d50" + }, + "cell_type": "code", + "source": [ + "d =np.ones(shape=(11,11))\n", + "d[1:-1,1:-1] = 0\n", + "print(d)" + ], + "execution_count": 16, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "xaQgf8tT9v-n", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "8) Create an 8 x 8 array with a checkerboard pattern of zeros and ones using a slicing+striding approach." + ] + }, + { + "metadata": { + "id": "No7fx0Xy9zEh", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 151 + }, + "outputId": "7bc64148-58d9-43fd-d1ec-f04166c37979" + }, + "cell_type": "code", + "source": [ + "x = np.ones((3,3))\n", + "x = np.zeros((8,8),dtype=int)\n", + "x[1::2,::2] = 1\n", + "x[::2,1::2] = 1\n", + "print(x)\n" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]\n", + " [0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]\n", + " [0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]\n", + " [0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]]\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 1b754a226ce8782d1e93c6af0d705fde167dfe12 Mon Sep 17 00:00:00 2001 From: Sayan46 <43204942+Sayan46@users.noreply.github.com> Date: Thu, 4 Oct 2018 21:28:20 +0530 Subject: [PATCH 3/3] Problem solved !