diff --git a/Anubhab-Bob.ipynb b/Anubhab-Bob.ipynb index 9e2543a..50191de 100644 --- a/Anubhab-Bob.ipynb +++ b/Anubhab-Bob.ipynb @@ -1,32 +1,31 @@ { - "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": "Anubhab-Bob.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": "A5gF9gMFq3Ck", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Anubhab_Bob_Assignment_2_Lists.ipynb b/Anubhab_Bob_Assignment_2_Lists.ipynb new file mode 100644 index 0000000..cfafc21 --- /dev/null +++ b/Anubhab_Bob_Assignment_2_Lists.ipynb @@ -0,0 +1,298 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Anubhab_Bob (1).ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/Anubhab-Bob/Assignment-2/blob/Anubhab-Bob/Anubhab_Bob_Assignment_2_Lists.ipynb)" + ] + }, + { + "metadata": { + "id": "A5gF9gMFq3Ck", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list=[1, 2, 3, 4, 5, 3]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "QkJs_byK_qPg", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "6517822b-da14-4727-f436-c101ba3ec661" + }, + "cell_type": "code", + "source": [ + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 3]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "F2QMHeQAB4Ja", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "print(sorted(dummy_list, reverse=True))" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "7XeXBwK6CD1i", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "3cefa005-b90a-4e72-8be7-24e06ea943fb" + }, + "cell_type": "code", + "source": [ + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "dummy_list.extend(dummy_list_2)\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 3, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "ujmdan92Du6g", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_dict={}" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "TPaUVjDSEqyv", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "i=0\n", + "while i!= len(dummy_list):\n", + " if dummy_list[i] not in dummy_dict:\n", + " dummy_dict[dummy_list[i]]=1\n", + " else:\n", + " for key,value in dummy_dict.items():\n", + " if key == dummy_list[i]:\n", + " dummy_dict[key] = value + 1\n", + " break\n", + " #print(\"Key: \" + str(key))\n", + " #print (\"Value: \" + str(value))\n", + " i = i + 1\n", + " #print(i)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "TY6jC_gyQbPP", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "for key, value in dummy_dict.items():\n", + " print(\"Key: \" + str(key))\n", + " print (\"Value: \" + str(value))\n", + " #print('\\n')" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "G0Ft30gsucvR", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 510 + }, + "outputId": "b3baa9d8-accc-4b8e-e76c-bd35a1052f3f" + }, + "cell_type": "code", + "source": [ + "for key in sorted(dummy_dict.keys()):\n", + " print (\"Key :\" + str(key) + '\\t\\t\\t' + \"Value :\" + str(dummy_dict[key]))\n", + "\n", + "print(\"\\n\\n\")\n", + "for key in sorted(dummy_dict.keys(), reverse=True):\n", + " print (\"Key :\" + str(key) + '\\t\\t\\t' + \"Value :\" + str(dummy_dict[key]))" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Key :0\t\t\tValue :1\n", + "Key :1\t\t\tValue :2\n", + "Key :2\t\t\tValue :2\n", + "Key :3\t\t\tValue :2\n", + "Key :4\t\t\tValue :2\n", + "Key :5\t\t\tValue :1\n", + "Key :9.45\t\t\tValue :1\n", + "Key :12.01\t\t\tValue :1\n", + "Key :12.02\t\t\tValue :1\n", + "Key :16\t\t\tValue :1\n", + "Key :45.67\t\t\tValue :1\n", + "Key :90\t\t\tValue :1\n", + "Key :200\t\t\tValue :1\n", + "\n", + "\n", + "\n", + "Key :200\t\t\tValue :1\n", + "Key :90\t\t\tValue :1\n", + "Key :45.67\t\t\tValue :1\n", + "Key :16\t\t\tValue :1\n", + "Key :12.02\t\t\tValue :1\n", + "Key :12.01\t\t\tValue :1\n", + "Key :9.45\t\t\tValue :1\n", + "Key :5\t\t\tValue :1\n", + "Key :4\t\t\tValue :2\n", + "Key :3\t\t\tValue :2\n", + "Key :2\t\t\tValue :2\n", + "Key :1\t\t\tValue :2\n", + "Key :0\t\t\tValue :1\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "DtOAyHUtvm8Z", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "7414ec65-9a45-4354-fa7a-4e8e8370fde8" + }, + "cell_type": "code", + "source": [ + "x=200\n", + "dummy_list.remove(x)\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 3, 2, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "Adi6fYUBwnFG", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "ccced705-37e8-45c6-e5ba-a223ace45e16" + }, + "cell_type": "code", + "source": [ + "del dummy_list[5]\n", + "print (dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 2, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "OTEasC7uxmOX", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "187e88b3-6f25-43ef-f133-ef3edc147094" + }, + "cell_type": "code", + "source": [ + "dummy_list.clear()\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[]\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file diff --git a/Assignment 2(Complete).ipynb b/Assignment 2(Complete).ipynb new file mode 100644 index 0000000..419db63 --- /dev/null +++ b/Assignment 2(Complete).ipynb @@ -0,0 +1,364 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Anubhab_Bob (1).ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/Anubhab-Bob/Assignment-2/blob/Anubhab-Bob/Assignment%202(Complete).ipynb)" + ] + }, + { + "metadata": { + "id": "A5gF9gMFq3Ck", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list=[1, 2, 3, 4, 5, 3]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "QkJs_byK_qPg", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "F2QMHeQAB4Ja", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "print(sorted(dummy_list, reverse=True))" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "7XeXBwK6CD1i", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "dummy_list.extend(dummy_list_2)\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "ujmdan92Du6g", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_dict={}" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "TPaUVjDSEqyv", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "i=0\n", + "while i!= len(dummy_list):\n", + " if dummy_list[i] not in dummy_dict:\n", + " dummy_dict[dummy_list[i]]=1\n", + " else:\n", + " for key,value in dummy_dict.items():\n", + " if key == dummy_list[i]:\n", + " dummy_dict[key] = value + 1\n", + " break\n", + " #print(\"Key: \" + str(key))\n", + " #print (\"Value: \" + str(value))\n", + " i = i + 1\n", + " #print(i)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "TY6jC_gyQbPP", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "for key, value in dummy_dict.items():\n", + " print(\"Key: \" + str(key))\n", + " print (\"Value: \" + str(value))\n", + " #print('\\n')" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "G0Ft30gsucvR", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "for key in sorted(dummy_dict.keys()):\n", + " print (\"Key :\" + str(key) + '\\t\\t\\t' + \"Value :\" + str(dummy_dict[key]))\n", + "\n", + "print(\"\\n\\n\")\n", + "for key in sorted(dummy_dict.keys(), reverse=True):\n", + " print (\"Key :\" + str(key) + '\\t\\t\\t' + \"Value :\" + str(dummy_dict[key]))" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "DtOAyHUtvm8Z", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "x=200\n", + "dummy_list.remove(x)\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "Adi6fYUBwnFG", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "del dummy_list[5]\n", + "print (dummy_list)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "OTEasC7uxmOX", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "dummy_list.clear()\n", + "print(dummy_list)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "XI0_hACCQlA_", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "import numpy as np" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "VV7zXbLnYp2t", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 204 + }, + "outputId": "e2e0fda2-13a1-40e3-a28e-2fa1253cdd70" + }, + "cell_type": "code", + "source": [ + "b = np.linspace(1.3,2.5, num=64)\n", + "print (b)" + ], + "execution_count": 21, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1.3 1.31904762 1.33809524 1.35714286 1.37619048 1.3952381\n", + " 1.41428571 1.43333333 1.45238095 1.47142857 1.49047619 1.50952381\n", + " 1.52857143 1.54761905 1.56666667 1.58571429 1.6047619 1.62380952\n", + " 1.64285714 1.66190476 1.68095238 1.7 1.71904762 1.73809524\n", + " 1.75714286 1.77619048 1.7952381 1.81428571 1.83333333 1.85238095\n", + " 1.87142857 1.89047619 1.90952381 1.92857143 1.94761905 1.96666667\n", + " 1.98571429 2.0047619 2.02380952 2.04285714 2.06190476 2.08095238\n", + " 2.1 2.11904762 2.13809524 2.15714286 2.17619048 2.1952381\n", + " 2.21428571 2.23333333 2.25238095 2.27142857 2.29047619 2.30952381\n", + " 2.32857143 2.34761905 2.36666667 2.38571429 2.4047619 2.42380952\n", + " 2.44285714 2.46190476 2.48095238 2.5 ]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "JYYLSWaQRKJC", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "n = int(input())\n", + "x = np.array([1, 2, 3])\n", + "y = np.tile(x,(3*n))\n", + "print (y)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "FGwwjf_pTMRs", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "b = np.arange(20)\n", + "\n", + "#print(b)\n", + "\n", + "mask = b%2!=0 #perform computations on the list \n", + "\n", + "#print(mask)\n", + "\n", + "print(b[mask]) #applying the mask on the numpy array" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "ZRDXe1q4Yw6C", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "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", + "np.intersect1d(a,b)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "vrIl330LZDO3", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "a = np.arange(10)\n", + "print (a)\n", + "a.shape = a.size//-1, 5\n", + "print(a)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "atGd8_9_Zjc-", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + "np.array(a).tolist()\n", + "print(a)\n", + "print('\\n')\n", + "np.asarray(a)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "L8JI_PAmbcbp", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "d = np.ones((5,5))\n", + "d[1:-1,1:-1] = 0\n", + "print(d)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "SY2a-sGxU4Q8", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "x = np.zeros((8,8),dtype=int)\n", + "x[1::2,::2] = 1\n", + "x[::2,1::2] = 1\n", + "print(x)" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file