diff --git a/Json/Converting_Python_object_containing_all_the_legal_data_types.ipynb b/Json/Converting_Python_object_containing_all_the_legal_data_types.ipynb new file mode 100644 index 0000000..943964a --- /dev/null +++ b/Json/Converting_Python_object_containing_all_the_legal_data_types.ipynb @@ -0,0 +1,68 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyNGSJJ+iuyj5ZBob0JkgoG6", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "6LrSXims3jdj", + "outputId": "88eaf273-3b87-4bb0-a59f-599b073b6780" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "{\"name\": \"John\", \"age\": 30, \"married\": true, \"divorced\": false, \"children\": [\"Ann\", \"Billy\"], \"pets\": null, \"cars\": [{\"model\": \"BMW 230\", \"mpg\": 27.5}, {\"model\": \"Ford Edge\", \"mpg\": 24.1}]}\n" + ] + } + ], + "source": [ + "import json\n", + "\n", + "x = {\n", + " \"name\": \"John\",\n", + " \"age\": 30,\n", + " \"married\": True,\n", + " \"divorced\": False,\n", + " \"children\": (\"Ann\",\"Billy\"),\n", + " \"pets\": None,\n", + " \"cars\": [\n", + " {\"model\": \"BMW 230\", \"mpg\": 27.5},\n", + " {\"model\": \"Ford Edge\", \"mpg\": 24.1}\n", + " ]\n", + "}\n", + "\n", + "print(json.dumps(x))\n" + ] + } + ] +} \ No newline at end of file diff --git a/PyTorch_Tensors_to_fit_a_third_order_polynomial_to_sine_function_.ipynb b/PyTorch_Tensors_to_fit_a_third_order_polynomial_to_sine_function_.ipynb new file mode 100644 index 0000000..bb530e4 --- /dev/null +++ b/PyTorch_Tensors_to_fit_a_third_order_polynomial_to_sine_function_.ipynb @@ -0,0 +1,83 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyMt56DabNBLu2zfWbH6oeH9", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ntcctNbd5zG8" + }, + "outputs": [], + "source": [ + "import torch\n", + "import math\n", + "\n", + "\n", + "dtype = torch.float\n", + "device = torch.device(\"cpu\")\n", + "# device = torch.device(\"cuda:0\") # Uncomment this to run on GPU\n", + "\n", + "# Create random input and output data\n", + "x = torch.linspace(-math.pi, math.pi, 2000, device=device, dtype=dtype)\n", + "y = torch.sin(x)\n", + "\n", + "# Randomly initialize weights\n", + "a = torch.randn((), device=device, dtype=dtype)\n", + "b = torch.randn((), device=device, dtype=dtype)\n", + "c = torch.randn((), device=device, dtype=dtype)\n", + "d = torch.randn((), device=device, dtype=dtype)\n", + "\n", + "learning_rate = 1e-6\n", + "for t in range(2000):\n", + " # Forward pass: compute predicted y\n", + " y_pred = a + b * x + c * x ** 2 + d * x ** 3\n", + "\n", + " # Compute and print loss\n", + " loss = (y_pred - y).pow(2).sum().item()\n", + " if t % 100 == 99:\n", + " print(t, loss)\n", + "\n", + " # Backprop to compute gradients of a, b, c, d with respect to loss\n", + " grad_y_pred = 2.0 * (y_pred - y)\n", + " grad_a = grad_y_pred.sum()\n", + " grad_b = (grad_y_pred * x).sum()\n", + " grad_c = (grad_y_pred * x ** 2).sum()\n", + " grad_d = (grad_y_pred * x ** 3).sum()\n", + "\n", + " # Update weights using gradient descent\n", + " a -= learning_rate * grad_a\n", + " b -= learning_rate * grad_b\n", + " c -= learning_rate * grad_c\n", + " d -= learning_rate * grad_d\n", + "\n", + "\n", + "print(f'Result: y = {a.item()} + {b.item()} x + {c.item()} x^2 + {d.item()} x^3')" + ] + } + ] +} \ No newline at end of file diff --git a/Untitled0.ipynb b/Untitled0.ipynb new file mode 100644 index 0000000..79a972a --- /dev/null +++ b/Untitled0.ipynb @@ -0,0 +1,53 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyPc0lLR8A+7DCW7vCUNzoU2", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "J25Ag0V0meLA", + "outputId": "6d2d1ddf-096e-4a83-c3d2-7a3bcc98c085" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "amith\n" + ] + } + ], + "source": [ + "print(\"amith\")" + ] + } + ] +} \ No newline at end of file diff --git a/skiPy/Double_Integrals.ipynb b/skiPy/Double_Integrals.ipynb new file mode 100644 index 0000000..fd72c1b --- /dev/null +++ b/skiPy/Double_Integrals.ipynb @@ -0,0 +1,83 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyPoOxZlKRHjQLzp5Z472l3B", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "-yhh9MOSLk0G", + "outputId": "1d7ab912-5f54-4cff-d0bc-952e91bc0923" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", + "Requirement already satisfied: scipy in /usr/local/lib/python3.8/dist-packages (1.7.3)\n", + "Requirement already satisfied: numpy<1.23.0,>=1.16.5 in /usr/local/lib/python3.8/dist-packages (from scipy) (1.21.6)\n" + ] + } + ], + "source": [ + "! pip install scipy" + ] + }, + { + "cell_type": "code", + "source": [ + "from scipy import integrate\n", + "import numpy as np\n", + "f = lambda y, x: x*y**2\n", + "i = integrate.dblquad(f, 0, 2, lambda x: 0, lambda x: 1)\n", + "# print the results\n", + "print(i)\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "_dSQfyOCMhVw", + "outputId": "223896e0-c130-4152-8333-e0590fcfa02f" + }, + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(0.6666666666666667, 7.401486830834377e-15)\n" + ] + } + ] + } + ] +} \ No newline at end of file