From 682e677cdc68b8ddff2742a61be945316a416eb4 Mon Sep 17 00:00:00 2001 From: MalwareNinja Date: Wed, 10 Oct 2018 00:18:26 +0530 Subject: [PATCH 1/3] Minor fixes and Comments --- README.md | 4 ++-- solutions/1.1-subplots_and_basic_plotting.py | 2 ++ solutions/2.1-bar_and_fill_between.py | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 726412c..a692427 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Introduction -This tutorial is a complete re-imagining of how one should teach users +``This tutorial is a complete re-imagining of how one should teach users the matplotlib library. Hopefully, this tutorial may serve as inspiration for future restructuring of the matplotlib documentation. Plus, I have some -ideas of how to improve this tutorial. +ideas of how to improve this tutorial.`` Please fork and contribute back improvements! Feel free to use this tutorial for conferences and other opportunities for training. diff --git a/solutions/1.1-subplots_and_basic_plotting.py b/solutions/1.1-subplots_and_basic_plotting.py index 4a641d6..a826053 100644 --- a/solutions/1.1-subplots_and_basic_plotting.py +++ b/solutions/1.1-subplots_and_basic_plotting.py @@ -1,3 +1,4 @@ +# import required libraries import numpy as np import matplotlib.pyplot as plt @@ -11,4 +12,5 @@ ax.plot(x, y, color='black') ax.set(xticks=[], yticks=[], title=name) +#printing plot in IDE plt.show() diff --git a/solutions/2.1-bar_and_fill_between.py b/solutions/2.1-bar_and_fill_between.py index 125de02..0249d6f 100644 --- a/solutions/2.1-bar_and_fill_between.py +++ b/solutions/2.1-bar_and_fill_between.py @@ -1,8 +1,9 @@ +#import required libraries import numpy as np import matplotlib.pyplot as plt -np.random.seed(1) +np.random.seed(1) # generates exact same random values as they are here inside .seed(value) -# Generate data... +# Generate Random data... y_raw = np.random.randn(1000).cumsum() + 15 x_raw = np.linspace(0, 24, y_raw.size) @@ -23,8 +24,10 @@ # Now you're on your own! +#making sublots fig, ax = plt.subplots() +#Styling the Plot a little ... ax.plot(x_raw, y_raw, color=linecolor) ax.bar(x_pos, y_avg, width=bar_width, color=barcolor, yerr=y_err, ecolor='gray', edgecolor='gray') From df0598a5537e52e86139b8acc3d4fb06d139fc5c Mon Sep 17 00:00:00 2001 From: Stephen Fernandes <32235549+StephennFernandes@users.noreply.github.com> Date: Sun, 7 Apr 2019 16:12:35 +0530 Subject: [PATCH 2/3] Created using Colaboratory --- Pytorch practice code.ipynb | 135 ++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 Pytorch practice code.ipynb diff --git a/Pytorch practice code.ipynb b/Pytorch practice code.ipynb new file mode 100644 index 0000000..bfe97d2 --- /dev/null +++ b/Pytorch practice code.ipynb @@ -0,0 +1,135 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Untitled0.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": [ + "\"Open" + ] + }, + { + "metadata": { + "id": "KksBEKprSsc0", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "import torch \n", + "from torch.autograd import Variable \n", + "dtype = torch.FloatTensor\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "JbP9zubcS05E", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "N , D_in , H , D_out = 64, 1000, 100, 10\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "3IxqSgITS8hs", + "colab_type": "code", + "outputId": "6e46a372-b2c4-46a8-927d-99798ca74891", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 257 + } + }, + "cell_type": "code", + "source": [ + "x=Variable(torch.randn(N , D_in).type(dtype), requires_grad=False)\n", + "y=Variable(torch.randn(N, D_out).type(dtype), requires_grad=False)\n", + "\n", + "w1 = Variable(torch.randn(D_in , H).type(dtype), requires_grad=True)\n", + "w2 = Variable(torch.randn(D_out , H).type(dtype), requires_grad=True)\n", + "\n", + "\n", + "learning_rate = 1e-6\n", + "for t in range(500):\n", + " \n", + " y_pred = x.mm(w1).clamp(min=0).mm(w2)\n", + " loss=(y_pred - y).pow(2).sum()\n", + " print(t, loss.data[0])\n", + " \n", + " w1.grad.data.zero_()\n", + " w2.grad.data.zero_()\n", + " \n", + " loss.backward()\n", + " \n", + " w1.data -= learning_rate * w1.grad.data\n", + " w2.data -= learning_rate * w2.grad.data\n", + " \n" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "error", + "ename": "RuntimeError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mt\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m500\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0my_pred\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mw1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclamp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmin\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mw2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 12\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my_pred\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mRuntimeError\u001b[0m: size mismatch, m1: [64 x 100], m2: [10 x 100] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:940" + ] + } + ] + }, + { + "metadata": { + "id": "36dGeou1VvtD", + "colab_type": "code", + "outputId": "25aa2c18-580c-4d39-9c2c-4de84bd9ffb0", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 257 + } + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "error", + "ename": "IndexError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;31m# (1,); loss.data[0] is a scalar value holding the loss.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0my_pred\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 35\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 36\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 37\u001b[0m \u001b[0;31m# Use autograd to compute the backward pass. This call will compute the\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mIndexError\u001b[0m: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number" + ] + } + ] + } + ] +} \ No newline at end of file From 7b9217f9ef14c5bf2e700ffceb9b1568e3e7fec8 Mon Sep 17 00:00:00 2001 From: Stephen Fernandes <32235549+StephennFernandes@users.noreply.github.com> Date: Sun, 7 Apr 2019 16:13:03 +0530 Subject: [PATCH 3/3] Delete Pytorch practice code.ipynb --- Pytorch practice code.ipynb | 135 ------------------------------------ 1 file changed, 135 deletions(-) delete mode 100644 Pytorch practice code.ipynb diff --git a/Pytorch practice code.ipynb b/Pytorch practice code.ipynb deleted file mode 100644 index bfe97d2..0000000 --- a/Pytorch practice code.ipynb +++ /dev/null @@ -1,135 +0,0 @@ -{ - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "Untitled0.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": [ - "\"Open" - ] - }, - { - "metadata": { - "id": "KksBEKprSsc0", - "colab_type": "code", - "colab": {} - }, - "cell_type": "code", - "source": [ - "import torch \n", - "from torch.autograd import Variable \n", - "dtype = torch.FloatTensor\n" - ], - "execution_count": 0, - "outputs": [] - }, - { - "metadata": { - "id": "JbP9zubcS05E", - "colab_type": "code", - "colab": {} - }, - "cell_type": "code", - "source": [ - "N , D_in , H , D_out = 64, 1000, 100, 10\n" - ], - "execution_count": 0, - "outputs": [] - }, - { - "metadata": { - "id": "3IxqSgITS8hs", - "colab_type": "code", - "outputId": "6e46a372-b2c4-46a8-927d-99798ca74891", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 257 - } - }, - "cell_type": "code", - "source": [ - "x=Variable(torch.randn(N , D_in).type(dtype), requires_grad=False)\n", - "y=Variable(torch.randn(N, D_out).type(dtype), requires_grad=False)\n", - "\n", - "w1 = Variable(torch.randn(D_in , H).type(dtype), requires_grad=True)\n", - "w2 = Variable(torch.randn(D_out , H).type(dtype), requires_grad=True)\n", - "\n", - "\n", - "learning_rate = 1e-6\n", - "for t in range(500):\n", - " \n", - " y_pred = x.mm(w1).clamp(min=0).mm(w2)\n", - " loss=(y_pred - y).pow(2).sum()\n", - " print(t, loss.data[0])\n", - " \n", - " w1.grad.data.zero_()\n", - " w2.grad.data.zero_()\n", - " \n", - " loss.backward()\n", - " \n", - " w1.data -= learning_rate * w1.grad.data\n", - " w2.data -= learning_rate * w2.grad.data\n", - " \n" - ], - "execution_count": 0, - "outputs": [ - { - "output_type": "error", - "ename": "RuntimeError", - "evalue": "ignored", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mt\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m500\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0my_pred\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mw1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclamp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmin\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mw2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 12\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my_pred\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mRuntimeError\u001b[0m: size mismatch, m1: [64 x 100], m2: [10 x 100] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:940" - ] - } - ] - }, - { - "metadata": { - "id": "36dGeou1VvtD", - "colab_type": "code", - "outputId": "25aa2c18-580c-4d39-9c2c-4de84bd9ffb0", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 257 - } - }, - "cell_type": "code", - "source": [ - "" - ], - "execution_count": 0, - "outputs": [ - { - "output_type": "error", - "ename": "IndexError", - "evalue": "ignored", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;31m# (1,); loss.data[0] is a scalar value holding the loss.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0my_pred\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 35\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 36\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 37\u001b[0m \u001b[0;31m# Use autograd to compute the backward pass. This call will compute the\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mIndexError\u001b[0m: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number" - ] - } - ] - } - ] -} \ No newline at end of file