diff --git a/AGCreates.ipynb b/AGCreates.ipynb index 9e2543a..be02be8 100644 --- a/AGCreates.ipynb +++ b/AGCreates.ipynb @@ -1,32 +1,256 @@ { - "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": "AGCreates.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "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": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/AGCreates/Assignment-2/blob/AGCreates/AGCreates.ipynb)" + ] + }, + { + "metadata": { + "id": "FTBef_OJr-Mu", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 136 + }, + "outputId": "607f64d3-512a-4b67-8c3c-be3d29a4f5be" + }, + "cell_type": "code", + "source": [ + "import random\n", + "dummy_list = [x for x in range (10)]\n", + "print (\"Dummy List\", dummy_list)\n", + "dummy_list.reverse()\n", + "print (\" Dummy List Reversed\", dummy_list)\n", + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "dummy_list= dummy_list + dummy_list_2\n", + "print(\"Dummy List after addition \", dummy_list)\n", + "\n", + "dummy_list_freq = []\n", + "dummy_list_unique = []\n", + "for x in dummy_list:\n", + " if x not in dummy_list_unique:\n", + " dummy_list_unique.append(x)\n", + "print (\" Dummy List Unique \",dummy_list_unique)\n", + "\n", + "for x in (dummy_list_unique):\n", + " counter=0\n", + " for y in (dummy_list):\n", + " if x==y:\n", + " counter= counter+1\n", + " dummy_list_freq.append(counter)\n", + " \n", + "dummy_dict = dict()\n", + "for i in range (len(dummy_list_unique)):\n", + " for j in range (len(dummy_list_freq)):\n", + " if i == j: dummy_dict[dummy_list_unique[i]] = dummy_list_freq[j]\n", + "print (\"Dummy Dictionary\", dummy_dict)\n", + "dummy_list.sort()\n", + "print (\"Dummy List Sorted Ascending Order\", dummy_list)\n", + "dummy_list.reverse()\n", + "print (\"Dummy List Sorted Descending Order\",dummy_list) \n", + "dummy_list.remove(200)\n", + "print (\"Dummy List Sorted After removing x= 200\", dummy_list)\n", + "index_remove = random.randint(0, len(dummy_list)-1)\n", + "print (\"Removing the value at radom index \", index_remove, \" which is \")\n", + "dummy_list.pop(index_remove)\n", + "print (\"Dummy List after removal of value at random index \", dummy_list)\n", + "print (\"Cleared Dummy List \", dummy_list.clear())" + ], + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Dummy List [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + " Dummy List Reversed [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n", + "Dummy List after addition [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + " Dummy List Unique [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 200, 16, 9.45, 45.67, 90, 12.01, 12.02]\n", + "Dummy Dictionary {9: 1, 8: 1, 7: 1, 6: 1, 5: 1, 4: 2, 3: 1, 2: 2, 1: 2, 0: 2, 200: 1, 16: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n", + "Dummy List Sorted Ascending Order [0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 9, 9.45, 12.01, 12.02, 16, 45.67, 90, 200]\n", + "Dummy List Sorted Descending Order [200, 90, 45.67, 16, 12.02, 12.01, 9.45, 9, 8, 7, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "7wkOxQUpzRl2", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 986 + }, + "outputId": "877ad255-e68e-4042-ea73-8d701553ec76" + }, + "cell_type": "code", + "source": [ + "import numpy as np\n", + "\n", + "#Numpy examples have been tried out but haven not been added here.\n", + "#This part consists of the Numpy Exercise only \n", + "\n", + "\n", + "unisub = np.linspace(-1.3, 2.5, 64)\n", + "print (\"Uniform Subdivision: \\n\", unisub) \n", + "\n", + "n = 8\n", + "cyc= np.array([1, 2, 3])\n", + "cyc = np.resize(cyc, 3 * n) \n", + "print(\"Cyclic Pattern \\n\", cyc) \n", + "\n", + "oddarr = np.arange(1, 2 * 10, 2)\n", + "print (\" First 10 odd int array:\\n\", oddarr) \n", + "\n", + "\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", + "\n", + "intersect = np.intersect1d(a, b)\n", + "print(\"Intersection array \\n\", intersect)\n", + "\n", + "a = np.arange(10)\n", + " \n", + "a = a.reshape(2, 5)\n", + " \n", + "print(\"Reshaped Array \\n\", a)\n", + "\n", + "\n", + "a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + " \n", + "a = np.array(a)\n", + "print(\"List to Numpy Array: \\n\", a)\n", + " \n", + "a= list(a)\n", + "print(\"Numpy Array to List: \\n\", a)\n", + "\n", + "\n", + "\n", + "\n", + "n = 10\n", + "arr = np.zeros(shape = (n, n))\n", + "print(\"Array of Zeroes: \\n\", arr)\n", + "print()\n", + "arr[n - 1, :] = np.ones(n)\n", + "arr[:, 0] = np.ones(n)\n", + "arr[:, n - 1] = np.ones(n)\n", + "arr[0, :] = np.ones(n)\n", + "print(\"Array of Zeroes bounded by 1:\\n\", arr)\n", + " \n", + "\n", + "n=8 \n", + " \n", + "print(\"Checkerboard:\")\n", + "x = np.zeros((n, n), dtype = int) \n", + "x[1::2, ::2] = 1\n", + "x[::2, 1::2] = 1\n", + " \n", + "for i in range(n): \n", + " for j in range(n): \n", + " print(x[i][j], end= \" \",) \n", + " print() \n", + " " + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Uniform Subdivision: \n", + " [-1.3 -1.23968254 -1.17936508 -1.11904762 -1.05873016 -0.9984127\n", + " -0.93809524 -0.87777778 -0.81746032 -0.75714286 -0.6968254 -0.63650794\n", + " -0.57619048 -0.51587302 -0.45555556 -0.3952381 -0.33492063 -0.27460317\n", + " -0.21428571 -0.15396825 -0.09365079 -0.03333333 0.02698413 0.08730159\n", + " 0.14761905 0.20793651 0.26825397 0.32857143 0.38888889 0.44920635\n", + " 0.50952381 0.56984127 0.63015873 0.69047619 0.75079365 0.81111111\n", + " 0.87142857 0.93174603 0.99206349 1.05238095 1.11269841 1.17301587\n", + " 1.23333333 1.29365079 1.35396825 1.41428571 1.47460317 1.53492063\n", + " 1.5952381 1.65555556 1.71587302 1.77619048 1.83650794 1.8968254\n", + " 1.95714286 2.01746032 2.07777778 2.13809524 2.1984127 2.25873016\n", + " 2.31904762 2.37936508 2.43968254 2.5 ]\n", + "Cyclic Pattern \n", + " [1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3]\n", + " First 10 odd int array:\n", + " [ 1 3 5 7 9 11 13 15 17 19]\n", + "Intersection array \n", + " [2 4]\n", + "Reshaped Array \n", + " [[0 1 2 3 4]\n", + " [5 6 7 8 9]]\n", + "List to Numpy Array: \n", + " [1 2 3 4 5 6 7 8 9]\n", + "Numpy Array to List: \n", + " [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + "Array of Zeroes: \n", + " [[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]\n", + "\n", + "Array of Zeroes bounded by 1:\n", + " [[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", + " [1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]\n", + "Checkerboard:\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", + "0 1 0 1 0 1 0 1 \n", + "1 0 1 0 1 0 1 0 \n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "dozwmoLWM_jJ", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Numpy_Examples_1.ipynb b/Numpy_Examples_1.ipynb index a8c1d0b..1d9207e 100644 --- a/Numpy_Examples_1.ipynb +++ b/Numpy_Examples_1.ipynb @@ -21,7 +21,7 @@ "colab_type": "text" }, "source": [ - "[View in Colaboratory](https://colab.research.google.com/github/abhiWriteCode/Assignment-2/blob/AGCreates/Numpy_Examples_1.ipynb)" + "\"Open" ] }, { @@ -82,9 +82,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 84 + "height": 85 }, - "outputId": "a7b8e482-f98d-4fce-e4d2-45746ea72626" + "outputId": "857d3efe-efa5-483e-a249-957096a97eb0" }, "cell_type": "code", "source": [ @@ -126,9 +126,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 217 + "height": 221 }, - "outputId": "7ef2b20f-b3bc-4ce6-bf0c-66db179616a9" + "outputId": "7b1964c2-45c4-49b8-9f09-793cd10d6df9" }, "cell_type": "code", "source": [ @@ -159,8 +159,8 @@ "d [[5 5 5]\n", " [5 5 5]\n", " [5 5 5]]\n", - "e [[0.13096102 0.89957882]\n", - " [0.23287877 0.6681981 ]]\n" + "e [[0.08873862 0.4361318 ]\n", + " [0.19152098 0.6743398 ]]\n" ], "name": "stdout" } @@ -182,39 +182,26 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 167 + "height": 51 }, - "outputId": "81e71c77-2b8d-4c1b-e854-19699d69db84" + "outputId": "447739b9-ef8d-410a-859d-aa684f5dfadf" }, "cell_type": "code", "source": [ "a == np.arange(10)\n", - "b == np.linspace(0,10, num=6)\n", + "b == np.linspace(0,10, num=6)\n", "print(a)\n", "print(b)" ], - "execution_count": 4, + "execution_count": 7, "outputs": [ { "output_type": "stream", "text": [ - "[[0. 0.]\n", - " [0. 0.]]\n", - "[[1. 1. 1.]\n", - " [1. 1. 1.]\n", - " [1. 1. 1.]]\n" + "[0 1 2 3 4 5 6 7 8 9]\n", + "[ 0. 2. 4. 6. 8. 10.]\n" ], "name": "stdout" - }, - { - "output_type": "stream", - "text": [ - "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:1: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.\n", - " \"\"\"Entry point for launching an IPython kernel.\n", - "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:2: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.\n", - " \n" - ], - "name": "stderr" } ] }, @@ -234,9 +221,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 50 + "height": 51 }, - "outputId": "5800f3ad-e227-403d-f7d2-5f57e5b10d4b" + "outputId": "4c371809-e687-44fa-dad4-f07ec9657d3a" }, "cell_type": "code", "source": [ @@ -256,7 +243,7 @@ "b[0, 0] = 77 # b[0, 0] is the same piece of data as a[0, 1]\n", "print(a[0, 1]) # Prints \"77\"" ], - "execution_count": 5, + "execution_count": 8, "outputs": [ { "output_type": "stream", @@ -284,9 +271,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 117 + "height": 119 }, - "outputId": "b6dda1a2-8e84-4404-fc84-5f33ee011823" + "outputId": "ee70891b-a521-44f0-d39c-cfa200f283dc" }, "cell_type": "code", "source": [ @@ -304,7 +291,7 @@ "print(col_r1, col_r1.shape) # Prints \"[ 2 6 10] (3,)\"\n", "print(col_r2, col_r2.shape)" ], - "execution_count": 6, + "execution_count": 9, "outputs": [ { "output_type": "stream", @@ -336,9 +323,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 67 + "height": 68 }, - "outputId": "a8bccc0a-09ad-4177-8e35-b348c41d9419" + "outputId": "a6687350-7968-4fa2-d314-23f4eb51b067" }, "cell_type": "code", "source": [ @@ -348,7 +335,7 @@ "print(np.sum(x, axis=0)) # Compute sum of each column; prints \"[4 6]\"\n", "print(np.sum(x, axis=1)) # Compute sum of each row; prints \"[3 7]\"" ], - "execution_count": 7, + "execution_count": 10, "outputs": [ { "output_type": "stream", @@ -377,9 +364,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 67 + "height": 68 }, - "outputId": "41eb3bbe-0f51-4130-953d-22325a1e537d" + "outputId": "aacee99e-0a0d-4511-b5f6-e5dbad8ca3ba" }, "cell_type": "code", "source": [ @@ -390,10 +377,9 @@ "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\n" ], - "execution_count": 8, + "execution_count": 11, "outputs": [ { "output_type": "stream", @@ -412,9 +398,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 33 + "height": 34 }, - "outputId": "73fd67ba-e423-4ead-d19c-e39c8a7cdca9" + "outputId": "62a9990a-9114-4bb1-8715-946e93df6a96" }, "cell_type": "code", "source": [ @@ -423,7 +409,7 @@ "\n", "print(modified_b)" ], - "execution_count": 9, + "execution_count": 12, "outputs": [ { "output_type": "stream", @@ -450,18 +436,17 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 117 + "height": 119 }, - "outputId": "428ef9da-689b-4732-9561-36c53f6009ad" + "outputId": "f709a398-9c0a-450e-b521-989f0dba70a7" }, "cell_type": "code", "source": [ "a = np.arange(9).reshape(3,3)\n", "print(a)\n", - "\n", "print(a[:, [1,0,2]])" ], - "execution_count": 10, + "execution_count": 13, "outputs": [ { "output_type": "stream", @@ -493,18 +478,18 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 117 + "height": 119 }, - "outputId": "0e26db0c-7bf4-40dd-ffbe-49da568728ac" + "outputId": "eacd1335-eb6f-45f9-c287-d3314758da2f" }, "cell_type": "code", "source": [ "a = np.arange(9).reshape(3,3)\n", "print(a)\n", "\n", - "print(a[[1,0,2], :])" + "print(a[[1,0,2], :]) #Changes made by AGCreates, a instead of arr" ], - "execution_count": 11, + "execution_count": 15, "outputs": [ { "output_type": "stream", @@ -519,6 +504,19 @@ "name": "stdout" } ] + }, + { + "metadata": { + "id": "ASJXUAR5FXl9", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "#This has bee done again by AGCreates to resolve merge conflicts." + ], + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file