From d1b85df74599498419dc4eff10666a9e3f711327 Mon Sep 17 00:00:00 2001 From: Nawaz Sk Date: Thu, 4 Oct 2018 22:25:14 +0530 Subject: [PATCH 1/8] Created using Colaboratory --- Lists.ipynb | 283 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 Lists.ipynb diff --git a/Lists.ipynb b/Lists.ipynb new file mode 100644 index 0000000..fd1c5d4 --- /dev/null +++ b/Lists.ipynb @@ -0,0 +1,283 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Lists.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/shadow9d/Assignment-2/blob/shadow9d/Lists.ipynb)" + ] + }, + { + "metadata": { + "id": "e0R1W0Vzm4UU", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# Exercise - List" + ] + }, + { + "metadata": { + "id": "TrO7XNQnnQZ7", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "1) Create any random list and assign it to a variable dummy_list" + ] + }, + { + "metadata": { + "id": "bjl-2QkznWid", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "cDjddNGfngnp", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "2) print dummy_list" + ] + }, + { + "metadata": { + "id": "RVL5178inz9M", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "15jKDXxkn16M", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "3) Reverse dummy_list and print" + ] + }, + { + "metadata": { + "id": "bYa9gFOOn-4o", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "EShv0nfXpUys", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "4) Add the list dummy_list_2 to the previous dummy_list and now print dummy_list" + ] + }, + { + "metadata": { + "id": "Ngkc7hnYphg6", + "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]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "Le1aRTuYoDzS", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "5) Create a dictionary named dummy_dict which contains all the elements of dummy_list as keys and frequency as values. " + ] + }, + { + "metadata": { + "id": "VHfSR_Csthnk", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "rtPC6WkSos-y", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "RgCYpFXGou6q", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "6) print dummy_dict" + ] + }, + { + "metadata": { + "id": "qe5E5IgxpTWU", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "8n_nsBDup4--", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "7) Sort dummy_list in ascending order as well as descending order and print the changed lists " + ] + }, + { + "metadata": { + "id": "Z_m7vr26qKnK", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "Znm5Qo4LqPKA", + "colab_type": "text" + }, + "cell_type": "markdown", + "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." + ] + }, + { + "metadata": { + "id": "1-8mlngDqYvS", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "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": [] + }, + { + "metadata": { + "id": "QPB6iGbeqviN", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "9) Remove the item at position x. x is any random integer" + ] + }, + { + "metadata": { + "id": "aMyo1gmRrVHo", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "bqQnnsr8rm6G", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "10) Let's clean everything clear the list and then print" + ] + }, + { + "metadata": { + "id": "qBC8lKpLrtJW", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file From a2716c74129fd3c66daed1ccdddfaa5f03bf66c0 Mon Sep 17 00:00:00 2001 From: Nawaz Sk Date: Sat, 6 Oct 2018 08:44:29 +0530 Subject: [PATCH 2/8] Created using Colaboratory --- Lists.ipynb | 122 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 100 insertions(+), 22 deletions(-) diff --git a/Lists.ipynb b/Lists.ipynb index fd1c5d4..bc16421 100644 --- a/Lists.ipynb +++ b/Lists.ipynb @@ -52,7 +52,11 @@ }, "cell_type": "code", "source": [ - "" + "import random\n", + "dummy_list = [0]\n", + "for x in range(10):\n", + " x = random.randint(1,999)\n", + " dummy_list.append(x)" ], "execution_count": 0, "outputs": [] @@ -71,14 +75,26 @@ "metadata": { "id": "RVL5178inz9M", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "b4cc673f-bf19-4753-8c4b-ee8e882bbca5" }, "cell_type": "code", "source": [ - "" + "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0, 861, 993, 17, 666, 414, 359, 779, 211, 197, 919]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -94,14 +110,27 @@ "metadata": { "id": "bYa9gFOOn-4o", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "74dca355-1ab9-477b-e518-376d4aea86b8" }, "cell_type": "code", "source": [ - "" + "dummy_list.reverse()\n", + "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[919, 197, 211, 779, 359, 414, 666, 17, 993, 861, 0]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -117,14 +146,30 @@ "metadata": { "id": "Ngkc7hnYphg6", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 54 + }, + "outputId": "d2441261-8fd6-470b-ac91-2db7d2cb73a7" }, "cell_type": "code", "source": [ - "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]" + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "x = len(dummy_list_2)\n", + "for i in range(0,x): #to eliminate the '[]' from the list\n", + " dummy_list.append(dummy_list_2[i])\n", + "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 13, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[919, 197, 211, 779, 359, 414, 666, 17, 993, 861, 0, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -144,7 +189,11 @@ }, "cell_type": "code", "source": [ - "" + "dummy_dict = {}\n", + "total = len(dummy_list)\n", + "for i in range(total):\n", + " temp = dummy_list[i]\n", + " dummy_dict[temp] = dummy_list.count(temp)" ], "execution_count": 0, "outputs": [] @@ -176,14 +225,26 @@ "metadata": { "id": "qe5E5IgxpTWU", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "f6947f91-86c6-4a6f-a748-650810247b05" }, "cell_type": "code", "source": [ - "" + "print(dummy_dict)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 16, + "outputs": [ + { + "output_type": "stream", + "text": [ + "{919: 1, 197: 1, 211: 1, 779: 1, 359: 1, 414: 1, 666: 1, 17: 1, 993: 1, 861: 1, 0: 4, 2: 3, 200: 3, 16: 3, 4: 3, 1: 3, 9.45: 3, 45.67: 3, 90: 3, 12.01: 3, 12.02: 3}\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -199,14 +260,30 @@ "metadata": { "id": "Z_m7vr26qKnK", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 70 + }, + "outputId": "9379efef-4de1-4c39-b387-f6af338d038b" }, "cell_type": "code", "source": [ - "" + "dummy_list.sort()\n", + "print(dummy_list)\n", + "dummy_list.sort(reverse=True)\n", + "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 18, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 4, 4, 4, 9.45, 9.45, 9.45, 12.01, 12.01, 12.01, 12.02, 12.02, 12.02, 16, 16, 16, 17, 45.67, 45.67, 45.67, 90, 90, 90, 197, 200, 200, 200, 211, 359, 414, 666, 779, 861, 919, 993]\n", + "[993, 919, 861, 779, 666, 414, 359, 211, 200, 200, 200, 197, 90, 90, 90, 45.67, 45.67, 45.67, 17, 16, 16, 16, 12.02, 12.02, 12.02, 12.01, 12.01, 12.01, 9.45, 9.45, 9.45, 4, 4, 4, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -228,6 +305,7 @@ "source": [ "x = 200\n", "\n", + "\n", "# Let's play: try the same with something which is not in the list to get the ValueError" ], "execution_count": 0, From a612cf1288e0b600abdd719d776242f2b548ad42 Mon Sep 17 00:00:00 2001 From: Nawaz Sk Date: Fri, 12 Oct 2018 13:27:04 +0530 Subject: [PATCH 3/8] list done --- Lists.ipynb | 139 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 108 insertions(+), 31 deletions(-) diff --git a/Lists.ipynb b/Lists.ipynb index bc16421..884eedc 100644 --- a/Lists.ipynb +++ b/Lists.ipynb @@ -79,18 +79,18 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "b4cc673f-bf19-4753-8c4b-ee8e882bbca5" + "outputId": "cf7f0e6a-3ee5-4fb0-d060-c81b3353535d" }, "cell_type": "code", "source": [ "print(dummy_list)" ], - "execution_count": 4, + "execution_count": 37, "outputs": [ { "output_type": "stream", "text": [ - "[0, 861, 993, 17, 666, 414, 359, 779, 211, 197, 919]\n" + "[0, 348, 315, 416, 958, 339, 738, 412, 553, 788, 596]\n" ], "name": "stdout" } @@ -114,19 +114,19 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "74dca355-1ab9-477b-e518-376d4aea86b8" + "outputId": "90ae5df1-12d8-477a-b50a-53c5dc383dbc" }, "cell_type": "code", "source": [ "dummy_list.reverse()\n", "print(dummy_list)" ], - "execution_count": 5, + "execution_count": 38, "outputs": [ { "output_type": "stream", "text": [ - "[919, 197, 211, 779, 359, 414, 666, 17, 993, 861, 0]\n" + "[596, 788, 553, 412, 738, 339, 958, 416, 315, 348, 0]\n" ], "name": "stdout" } @@ -148,9 +148,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 54 + "height": 34 }, - "outputId": "d2441261-8fd6-470b-ac91-2db7d2cb73a7" + "outputId": "febf8f13-3d33-4ca6-e342-d8433c078cf6" }, "cell_type": "code", "source": [ @@ -160,12 +160,12 @@ " dummy_list.append(dummy_list_2[i])\n", "print(dummy_list)" ], - "execution_count": 13, + "execution_count": 39, "outputs": [ { "output_type": "stream", "text": [ - "[919, 197, 211, 779, 359, 414, 666, 17, 993, 861, 0, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + "[596, 788, 553, 412, 738, 339, 958, 416, 315, 348, 0, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" ], "name": "stdout" } @@ -229,18 +229,18 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "f6947f91-86c6-4a6f-a748-650810247b05" + "outputId": "cdc3db98-cba4-4bdd-e7a1-7fa529ee8252" }, "cell_type": "code", "source": [ "print(dummy_dict)" ], - "execution_count": 16, + "execution_count": 41, "outputs": [ { "output_type": "stream", "text": [ - "{919: 1, 197: 1, 211: 1, 779: 1, 359: 1, 414: 1, 666: 1, 17: 1, 993: 1, 861: 1, 0: 4, 2: 3, 200: 3, 16: 3, 4: 3, 1: 3, 9.45: 3, 45.67: 3, 90: 3, 12.01: 3, 12.02: 3}\n" + "{596: 1, 788: 1, 553: 1, 412: 1, 738: 1, 339: 1, 958: 1, 416: 1, 315: 1, 348: 1, 0: 2, 2: 1, 200: 1, 16: 1, 4: 1, 1: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n" ], "name": "stdout" } @@ -262,9 +262,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 70 + "height": 50 }, - "outputId": "9379efef-4de1-4c39-b387-f6af338d038b" + "outputId": "eabfc39a-709d-4288-dbe0-e711c1331135" }, "cell_type": "code", "source": [ @@ -273,13 +273,13 @@ "dummy_list.sort(reverse=True)\n", "print(dummy_list)" ], - "execution_count": 18, + "execution_count": 42, "outputs": [ { "output_type": "stream", "text": [ - "[0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 4, 4, 4, 9.45, 9.45, 9.45, 12.01, 12.01, 12.01, 12.02, 12.02, 12.02, 16, 16, 16, 17, 45.67, 45.67, 45.67, 90, 90, 90, 197, 200, 200, 200, 211, 359, 414, 666, 779, 861, 919, 993]\n", - "[993, 919, 861, 779, 666, 414, 359, 211, 200, 200, 200, 197, 90, 90, 90, 45.67, 45.67, 45.67, 17, 16, 16, 16, 12.02, 12.02, 12.02, 12.01, 12.01, 12.01, 9.45, 9.45, 9.45, 4, 4, 4, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0]\n" + "[0, 0, 1, 2, 4, 9.45, 12.01, 12.02, 16, 45.67, 90, 200, 315, 339, 348, 412, 416, 553, 596, 738, 788, 958]\n", + "[958, 788, 738, 596, 553, 416, 412, 348, 339, 315, 200, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0, 0]\n" ], "name": "stdout" } @@ -299,17 +299,40 @@ "metadata": { "id": "1-8mlngDqYvS", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "66262ef5-55f0-41fd-e2fa-ec6d3adf741a" }, "cell_type": "code", "source": [ "x = 200\n", + "dummy_list.remove(x)\n", + "print(dummy_list)\n", "\n", - "\n", + "#dummy_list.remove(13) \n", + "#ValueError Traceback (most recent call last)\n", + "# in ()\n", + "# 1 x = 200\n", + "#---> 2 dummy_list.remove(x)\n", + "# 3 print(dummy_list)\n", + "# 4 dummy_list.remove(13)\n", + "# 5 \n", + "#\n", + "#ValueError: list.remove(x): x not in list\n", "# Let's play: try the same with something which is not in the list to get the ValueError" ], - "execution_count": 0, - "outputs": [] + "execution_count": 43, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[958, 788, 738, 596, 553, 416, 412, 348, 339, 315, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0, 0]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -323,16 +346,30 @@ }, { "metadata": { - "id": "aMyo1gmRrVHo", + "id": "NakdzAYoRLwv", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "abf64fa4-a486-487b-9d34-6b85d70eddce" }, "cell_type": "code", "source": [ - "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get" + "x = 5\n", + "dummy_list.pop(x)\n", + "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 45, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[958, 788, 738, 596, 553, 412, 348, 339, 315, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 0, 0]\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -344,18 +381,58 @@ "10) Let's clean everything clear the list and then print" ] }, + { + "metadata": { + "id": "aMyo1gmRrVHo", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "77cfac80-ecc0-4375-9485-5c902b7eda5b" + }, + "cell_type": "code", + "source": [ + "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get\n", + "dummy_list.remove(x > len(dummy_list) + 1)\n", + "print(dummy_list)" + ], + "execution_count": 44, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[958, 788, 738, 596, 553, 416, 412, 348, 339, 315, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 0, 0]\n" + ], + "name": "stdout" + } + ] + }, { "metadata": { "id": "qBC8lKpLrtJW", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "594fab88-a122-4e01-d373-824afb48aa89" }, "cell_type": "code", "source": [ - "" + "dummy_list.clear()\n", + "print(dummy_list)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 46, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[]\n" + ], + "name": "stdout" + } + ] } ] } \ No newline at end of file From fd33934ee68e6cdb14aad2b59dfffcc65f50e323 Mon Sep 17 00:00:00 2001 From: Nawaz Sk Date: Fri, 12 Oct 2018 18:17:29 +0530 Subject: [PATCH 4/8] Created using Colaboratory --- Numpy_Exercises.ipynb | 266 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 Numpy_Exercises.ipynb diff --git a/Numpy_Exercises.ipynb b/Numpy_Exercises.ipynb new file mode 100644 index 0000000..489b278 --- /dev/null +++ b/Numpy_Exercises.ipynb @@ -0,0 +1,266 @@ +{ + "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/shadow9d/Assignment-2/blob/shadow9d/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": {} + }, + "cell_type": "code", + "source": [ + "import numpy as np #import numpy" + ], + "execution_count": 0, + "outputs": [] + }, + { + "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": 84 + }, + "outputId": "24ee9d94-1f68-4672-9804-53eded0d78da" + }, + "cell_type": "code", + "source": [ + "n = 4\n", + "arr = np.zeros(shape=(n,3))\n", + "for i in range(n):\n", + " arr[i][0] = 1\n", + " arr[i][1] = 2\n", + " arr[i][2] = 3\n", + " \n", + "print(arr)" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[1. 2. 3.]\n", + " [1. 2. 3.]\n", + " [1. 2. 3.]\n", + " [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": "11cba838-51a6-4c7b-f29f-a21ecf25751c" + }, + "cell_type": "code", + "source": [ + "array_odd = np.arange(1,20,2)\n", + "print(array_odd)" + ], + "execution_count": 5, + "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": "f406c1e8-2ad6-4c8c-c1d1-e65f12b77ddc" + }, + "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", + "print(np.intersect1d(a,b))" + ], + "execution_count": 6, + "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": {} + }, + "cell_type": "code", + "source": [ + "a = np.arange(10)\n", + "a.reshape(2,5)\n", + "print(a)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "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": {} + }, + "cell_type": "code", + "source": [ + "a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "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": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "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": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file From 6034f94e9eea41b959a2ed8fb82d0c889553bbad Mon Sep 17 00:00:00 2001 From: Nawaz Sk Date: Fri, 12 Oct 2018 18:35:11 +0530 Subject: [PATCH 5/8] Created using Colaboratory --- Numpy_Exercises.ipynb | 99 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 19 deletions(-) diff --git a/Numpy_Exercises.ipynb b/Numpy_Exercises.ipynb index 489b278..4c99958 100644 --- a/Numpy_Exercises.ipynb +++ b/Numpy_Exercises.ipynb @@ -67,7 +67,7 @@ "base_uri": "https://localhost:8080/", "height": 84 }, - "outputId": "24ee9d94-1f68-4672-9804-53eded0d78da" + "outputId": "7a8d66c0-484a-470f-96ba-7e00219700c1" }, "cell_type": "code", "source": [ @@ -80,7 +80,7 @@ " \n", "print(arr)" ], - "execution_count": 3, + "execution_count": 2, "outputs": [ { "output_type": "stream", @@ -112,14 +112,14 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "11cba838-51a6-4c7b-f29f-a21ecf25751c" + "outputId": "9bcf6241-38e1-412a-a938-2f23899bfa47" }, "cell_type": "code", "source": [ "array_odd = np.arange(1,20,2)\n", "print(array_odd)" ], - "execution_count": 5, + "execution_count": 3, "outputs": [ { "output_type": "stream", @@ -148,7 +148,7 @@ "base_uri": "https://localhost:8080/", "height": 34 }, - "outputId": "f406c1e8-2ad6-4c8c-c1d1-e65f12b77ddc" + "outputId": "efffcd93-ef7f-4ac5-f945-0c4a94960a1c" }, "cell_type": "code", "source": [ @@ -157,7 +157,7 @@ "b = np.array([7,2,10,2,7,4,9,4,9,8])\n", "print(np.intersect1d(a,b))" ], - "execution_count": 6, + "execution_count": 4, "outputs": [ { "output_type": "stream", @@ -182,16 +182,30 @@ "metadata": { "id": "2E8b55_2Cjx5", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 50 + }, + "outputId": "966b1f53-bbfc-478d-fa51-7a6bb4be4c85" }, "cell_type": "code", "source": [ "a = np.arange(10)\n", - "a.reshape(2,5)\n", - "print(a)" + "print(a.shape)\n", + "a = a.reshape(2,5)\n", + "print(a.shape)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 10, + "outputs": [ + { + "output_type": "stream", + "text": [ + "(10,)\n", + "(2, 5)\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -207,14 +221,30 @@ "metadata": { "id": "tcBCyhXPEp9C", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 50 + }, + "outputId": "ecd657f3-c08a-4d58-b691-45981aeb72e2" }, "cell_type": "code", "source": [ - "a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n" + "a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + "print(type(a))\n", + "new_arr = np.array(a)\n", + "print(type(new_arr))" ], - "execution_count": 0, - "outputs": [] + "execution_count": 14, + "outputs": [ + { + "output_type": "stream", + "text": [ + "\n", + "\n" + ], + "name": "stdout" + } + ] }, { "metadata": { @@ -230,14 +260,45 @@ "metadata": { "id": "4bjP3JAc9vRD", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 185 + }, + "outputId": "a54ed72d-a3be-45b3-9400-b5908b6b8911" }, "cell_type": "code", "source": [ - "" + "arr = np.zeros(shape = (10,10))\n", + "def border(arr,min,max,bor):\n", + " for i in range(max + 1):\n", + " arr[min][i] = bor\n", + " arr[i][min] = bor\n", + " arr[max][i] = bor\n", + " arr[i][max] = bor\n", + " return arr\n", + "\n", + "arr = border(arr,0,9,1)\n", + "print(arr)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 20, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[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" + ], + "name": "stdout" + } + ] }, { "metadata": { From 598afffe95b7d812bc4b7aad0a8344ce151ef2b9 Mon Sep 17 00:00:00 2001 From: Nawaz Sk Date: Fri, 12 Oct 2018 18:47:30 +0530 Subject: [PATCH 6/8] Created using Colaboratory --- Numpy_Exercises.ipynb | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Numpy_Exercises.ipynb b/Numpy_Exercises.ipynb index 4c99958..ea0d57f 100644 --- a/Numpy_Exercises.ipynb +++ b/Numpy_Exercises.ipynb @@ -262,9 +262,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 185 + "height": 50 }, - "outputId": "a54ed72d-a3be-45b3-9400-b5908b6b8911" + "outputId": "eef199ce-f6f0-4963-f222-1441e2670222" }, "cell_type": "code", "source": [ @@ -278,23 +278,19 @@ " return arr\n", "\n", "arr = border(arr,0,9,1)\n", - "print(arr)" + "#print(arr)\n", + "\n", + "arr = np.zeros(shape = (10,10))\n", + "print(arr[1:3,1:5])\n", + "#print(arr)" ], - "execution_count": 20, + "execution_count": 24, "outputs": [ { "output_type": "stream", "text": [ - "[[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" + "[[0. 0. 0. 0.]\n", + " [0. 0. 0. 0.]]\n" ], "name": "stdout" } From 94c0d2b13f7a457dc89372dc6bc1572f5aca599c Mon Sep 17 00:00:00 2001 From: Nawaz Sk Date: Thu, 17 Jan 2019 22:47:20 +0530 Subject: [PATCH 7/8] Done. --- Lists.ipynb | 137 ++++++++++++++++++---------------------------------- 1 file changed, 46 insertions(+), 91 deletions(-) diff --git a/Lists.ipynb b/Lists.ipynb index 884eedc..dab5c12 100644 --- a/Lists.ipynb +++ b/Lists.ipynb @@ -5,8 +5,7 @@ "colab": { "name": "Lists.ipynb", "version": "0.3.2", - "provenance": [], - "include_colab_link": true + "provenance": [] }, "kernelspec": { "name": "python3", @@ -14,16 +13,6 @@ } }, "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "[View in Colaboratory](https://colab.research.google.com/github/shadow9d/Assignment-2/blob/shadow9d/Lists.ipynb)" - ] - }, { "metadata": { "id": "e0R1W0Vzm4UU", @@ -75,22 +64,22 @@ "metadata": { "id": "RVL5178inz9M", "colab_type": "code", + "outputId": "498ef785-47a4-4a5b-ef9b-8f536a7e9928", "colab": { "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "cf7f0e6a-3ee5-4fb0-d060-c81b3353535d" + "height": 35 + } }, "cell_type": "code", "source": [ "print(dummy_list)" ], - "execution_count": 37, + "execution_count": 2, "outputs": [ { "output_type": "stream", "text": [ - "[0, 348, 315, 416, 958, 339, 738, 412, 553, 788, 596]\n" + "[0, 354, 225, 129, 442, 101, 71, 584, 580, 553, 216]\n" ], "name": "stdout" } @@ -110,23 +99,23 @@ "metadata": { "id": "bYa9gFOOn-4o", "colab_type": "code", + "outputId": "f4d178ac-5227-4ab0-a9a5-0ddfedbe94a5", "colab": { "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "90ae5df1-12d8-477a-b50a-53c5dc383dbc" + "height": 35 + } }, "cell_type": "code", "source": [ "dummy_list.reverse()\n", "print(dummy_list)" ], - "execution_count": 38, + "execution_count": 3, "outputs": [ { "output_type": "stream", "text": [ - "[596, 788, 553, 412, 738, 339, 958, 416, 315, 348, 0]\n" + "[216, 553, 580, 584, 71, 101, 442, 129, 225, 354, 0]\n" ], "name": "stdout" } @@ -146,11 +135,11 @@ "metadata": { "id": "Ngkc7hnYphg6", "colab_type": "code", + "outputId": "2507ad53-6f9e-4bed-e74f-e174452b7ca5", "colab": { "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "febf8f13-3d33-4ca6-e342-d8433c078cf6" + "height": 35 + } }, "cell_type": "code", "source": [ @@ -160,12 +149,12 @@ " dummy_list.append(dummy_list_2[i])\n", "print(dummy_list)" ], - "execution_count": 39, + "execution_count": 4, "outputs": [ { "output_type": "stream", "text": [ - "[596, 788, 553, 412, 738, 339, 958, 416, 315, 348, 0, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" + "[216, 553, 580, 584, 71, 101, 442, 129, 225, 354, 0, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n" ], "name": "stdout" } @@ -225,22 +214,22 @@ "metadata": { "id": "qe5E5IgxpTWU", "colab_type": "code", + "outputId": "d3c5edcf-e7f5-4790-9a27-7654e7412a96", "colab": { "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "cdc3db98-cba4-4bdd-e7a1-7fa529ee8252" + "height": 35 + } }, "cell_type": "code", "source": [ "print(dummy_dict)" ], - "execution_count": 41, + "execution_count": 6, "outputs": [ { "output_type": "stream", "text": [ - "{596: 1, 788: 1, 553: 1, 412: 1, 738: 1, 339: 1, 958: 1, 416: 1, 315: 1, 348: 1, 0: 2, 2: 1, 200: 1, 16: 1, 4: 1, 1: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n" + "{216: 1, 553: 1, 580: 1, 584: 1, 71: 1, 101: 1, 442: 1, 129: 1, 225: 1, 354: 1, 0: 2, 2: 1, 200: 1, 16: 1, 4: 1, 1: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n" ], "name": "stdout" } @@ -260,11 +249,11 @@ "metadata": { "id": "Z_m7vr26qKnK", "colab_type": "code", + "outputId": "b93e549e-60d2-4b22-ab22-22d723f43b8b", "colab": { "base_uri": "https://localhost:8080/", - "height": 50 - }, - "outputId": "eabfc39a-709d-4288-dbe0-e711c1331135" + "height": 53 + } }, "cell_type": "code", "source": [ @@ -273,13 +262,13 @@ "dummy_list.sort(reverse=True)\n", "print(dummy_list)" ], - "execution_count": 42, + "execution_count": 7, "outputs": [ { "output_type": "stream", "text": [ - "[0, 0, 1, 2, 4, 9.45, 12.01, 12.02, 16, 45.67, 90, 200, 315, 339, 348, 412, 416, 553, 596, 738, 788, 958]\n", - "[958, 788, 738, 596, 553, 416, 412, 348, 339, 315, 200, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0, 0]\n" + "[0, 0, 1, 2, 4, 9.45, 12.01, 12.02, 16, 45.67, 71, 90, 101, 129, 200, 216, 225, 354, 442, 553, 580, 584]\n", + "[584, 580, 553, 442, 354, 225, 216, 200, 129, 101, 90, 71, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0, 0]\n" ], "name": "stdout" } @@ -299,11 +288,11 @@ "metadata": { "id": "1-8mlngDqYvS", "colab_type": "code", + "outputId": "eaa954d6-91c4-4556-878b-457bd0f59a97", "colab": { "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "66262ef5-55f0-41fd-e2fa-ec6d3adf741a" + "height": 35 + } }, "cell_type": "code", "source": [ @@ -323,12 +312,12 @@ "#ValueError: list.remove(x): x not in list\n", "# Let's play: try the same with something which is not in the list to get the ValueError" ], - "execution_count": 43, + "execution_count": 8, "outputs": [ { "output_type": "stream", "text": [ - "[958, 788, 738, 596, 553, 416, 412, 348, 339, 315, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0, 0]\n" + "[584, 580, 553, 442, 354, 225, 216, 129, 101, 90, 71, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0, 0]\n" ], "name": "stdout" } @@ -348,28 +337,21 @@ "metadata": { "id": "NakdzAYoRLwv", "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "abf64fa4-a486-487b-9d34-6b85d70eddce" + "colab": {} }, "cell_type": "code", "source": [ - "x = 5\n", - "dummy_list.pop(x)\n", - "print(dummy_list)" + "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get\n", + "import random\n", + "x = random.randint(0,len(dummy_list))\n", + "dummy_list.remove(x)\n", + "\n", + "#to get the value errors\n", + "#x = len(dummy_list) + 1\n", + "#dummy_list.remove(x)" ], - "execution_count": 45, - "outputs": [ - { - "output_type": "stream", - "text": [ - "[958, 788, 738, 596, 553, 412, 348, 339, 315, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 0, 0]\n" - ], - "name": "stdout" - } - ] + "execution_count": 0, + "outputs": [] }, { "metadata": { @@ -385,45 +367,18 @@ "metadata": { "id": "aMyo1gmRrVHo", "colab_type": "code", + "outputId": "e932f27d-579e-482f-e913-77df3c2ec5e9", "colab": { "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "77cfac80-ecc0-4375-9485-5c902b7eda5b" - }, - "cell_type": "code", - "source": [ - "# Let's play: try doing the same with x > len(dummy_list) + 1 and see what you get\n", - "dummy_list.remove(x > len(dummy_list) + 1)\n", - "print(dummy_list)" - ], - "execution_count": 44, - "outputs": [ - { - "output_type": "stream", - "text": [ - "[958, 788, 738, 596, 553, 416, 412, 348, 339, 315, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 0, 0]\n" - ], - "name": "stdout" + "height": 35 } - ] - }, - { - "metadata": { - "id": "qBC8lKpLrtJW", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "594fab88-a122-4e01-d373-824afb48aa89" }, "cell_type": "code", "source": [ "dummy_list.clear()\n", "print(dummy_list)" ], - "execution_count": 46, + "execution_count": 10, "outputs": [ { "output_type": "stream", From 4a6af5b19060edd37c957f84fbd88f48a03f6c9d Mon Sep 17 00:00:00 2001 From: Nawaz Sk Date: Fri, 18 Jan 2019 00:12:20 +0530 Subject: [PATCH 8/8] Done --- Numpy_Exercises.ipynb | 131 +++++++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 58 deletions(-) diff --git a/Numpy_Exercises.ipynb b/Numpy_Exercises.ipynb index ea0d57f..5fdc567 100644 --- a/Numpy_Exercises.ipynb +++ b/Numpy_Exercises.ipynb @@ -5,8 +5,7 @@ "colab": { "name": "Numpy_Exercises.ipynb", "version": "0.3.2", - "provenance": [], - "include_colab_link": true + "provenance": [] }, "kernelspec": { "name": "python3", @@ -14,16 +13,6 @@ } }, "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "[View in Colaboratory](https://colab.research.google.com/github/shadow9d/Assignment-2/blob/shadow9d/Numpy_Exercises.ipynb)" - ] - }, { "metadata": { "id": "a_4UupTr9fbX", @@ -63,16 +52,16 @@ "metadata": { "id": "4TxT66309n1o", "colab_type": "code", + "outputId": "c5cca493-2e3d-4ccd-f185-8ca9f485ee05", "colab": { "base_uri": "https://localhost:8080/", - "height": 84 - }, - "outputId": "7a8d66c0-484a-470f-96ba-7e00219700c1" + "height": 89 + } }, "cell_type": "code", "source": [ "n = 4\n", - "arr = np.zeros(shape=(n,3))\n", + "arr = np.zeros(shape=(n,3),dtype=int)\n", "for i in range(n):\n", " arr[i][0] = 1\n", " arr[i][1] = 2\n", @@ -80,15 +69,15 @@ " \n", "print(arr)" ], - "execution_count": 2, + "execution_count": 33, "outputs": [ { "output_type": "stream", "text": [ - "[[1. 2. 3.]\n", - " [1. 2. 3.]\n", - " [1. 2. 3.]\n", - " [1. 2. 3.]]\n" + "[[1 2 3]\n", + " [1 2 3]\n", + " [1 2 3]\n", + " [1 2 3]]\n" ], "name": "stdout" } @@ -108,18 +97,18 @@ "metadata": { "id": "ebhEUZq29r32", "colab_type": "code", + "outputId": "0998a44d-42b9-4012-d8a6-ff678071207b", "colab": { "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "9bcf6241-38e1-412a-a938-2f23899bfa47" + "height": 35 + } }, "cell_type": "code", "source": [ "array_odd = np.arange(1,20,2)\n", "print(array_odd)" ], - "execution_count": 3, + "execution_count": 34, "outputs": [ { "output_type": "stream", @@ -144,11 +133,11 @@ "metadata": { "id": "gOlfuJCo-JwF", "colab_type": "code", + "outputId": "c75a3ae3-7829-4f51-8f8c-f40238544db1", "colab": { "base_uri": "https://localhost:8080/", - "height": 34 - }, - "outputId": "efffcd93-ef7f-4ac5-f945-0c4a94960a1c" + "height": 35 + } }, "cell_type": "code", "source": [ @@ -157,7 +146,7 @@ "b = np.array([7,2,10,2,7,4,9,4,9,8])\n", "print(np.intersect1d(a,b))" ], - "execution_count": 4, + "execution_count": 35, "outputs": [ { "output_type": "stream", @@ -182,11 +171,11 @@ "metadata": { "id": "2E8b55_2Cjx5", "colab_type": "code", + "outputId": "0daf38d8-f8d5-4792-bea4-d1f45e99131e", "colab": { "base_uri": "https://localhost:8080/", - "height": 50 - }, - "outputId": "966b1f53-bbfc-478d-fa51-7a6bb4be4c85" + "height": 53 + } }, "cell_type": "code", "source": [ @@ -195,7 +184,7 @@ "a = a.reshape(2,5)\n", "print(a.shape)" ], - "execution_count": 10, + "execution_count": 36, "outputs": [ { "output_type": "stream", @@ -221,11 +210,11 @@ "metadata": { "id": "tcBCyhXPEp9C", "colab_type": "code", + "outputId": "5f98e987-aa52-46d0-8818-fa8e0f029fbe", "colab": { "base_uri": "https://localhost:8080/", - "height": 50 - }, - "outputId": "ecd657f3-c08a-4d58-b691-45981aeb72e2" + "height": 53 + } }, "cell_type": "code", "source": [ @@ -234,7 +223,7 @@ "new_arr = np.array(a)\n", "print(type(new_arr))" ], - "execution_count": 14, + "execution_count": 37, "outputs": [ { "output_type": "stream", @@ -260,37 +249,40 @@ "metadata": { "id": "4bjP3JAc9vRD", "colab_type": "code", + "outputId": "aad80464-6a17-4dc7-b63f-0ed9fb32079d", "colab": { "base_uri": "https://localhost:8080/", - "height": 50 - }, - "outputId": "eef199ce-f6f0-4963-f222-1441e2670222" + "height": 197 + } }, "cell_type": "code", "source": [ - "arr = np.zeros(shape = (10,10))\n", + "arr = np.zeros(shape = (10,10),dtype=int)\n", "def border(arr,min,max,bor):\n", - " for i in range(max + 1):\n", - " arr[min][i] = bor\n", - " arr[i][min] = bor\n", - " arr[max][i] = bor\n", - " arr[i][max] = bor\n", + " arr[min, :] = 1\n", + " arr[:, min] = 1\n", + " arr[max, :] = 1\n", + " arr[:, max] = 1\n", " return arr\n", "\n", "arr = border(arr,0,9,1)\n", - "#print(arr)\n", - "\n", - "arr = np.zeros(shape = (10,10))\n", - "print(arr[1:3,1:5])\n", - "#print(arr)" + "print(arr)\n" ], - "execution_count": 24, + "execution_count": 38, "outputs": [ { "output_type": "stream", "text": [ - "[[0. 0. 0. 0.]\n", - " [0. 0. 0. 0.]]\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" ], "name": "stdout" } @@ -310,14 +302,37 @@ "metadata": { "id": "No7fx0Xy9zEh", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 161 + }, + "outputId": "203beecb-7925-44a6-b276-4e3da26d6469" }, "cell_type": "code", "source": [ - "" + "import numpy as np\n", + "arr = np.zeros((8,8),dtype=int)\n", + "arr[1::2,::2] = 1\n", + "arr[::2,1::2] = 1\n", + "print(arr)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 41, + "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