From 27792f4f3540ebf375adb3e4b3b908e3ae13b893 Mon Sep 17 00:00:00 2001 From: Xilliano <106842023+Xilliano@users.noreply.github.com> Date: Sat, 19 Oct 2024 15:31:07 -0400 Subject: [PATCH 1/3] Update manifest.json add mit to schools --- plugin/manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/manifest.json b/plugin/manifest.json index 6db51c6..d7d5c3d 100644 --- a/plugin/manifest.json +++ b/plugin/manifest.json @@ -225,7 +225,8 @@ "https://canvas.kdg.be/*", "https://canvas.liverpool.ac.uk/*", "https://canvas.moravian.edu/*", - "https://canvas-prod.ccsnh.edu/*" + "https://canvas-prod.ccsnh.edu/*", + "https://canvas.mit.edu/*" ], "css":[ "css/styles.css" From f74569e3489974b7c9d0bd343fd4b60b30ffcdb5 Mon Sep 17 00:00:00 2001 From: Xilliano <106842023+Xilliano@users.noreply.github.com> Date: Sun, 3 Nov 2024 22:28:13 -0500 Subject: [PATCH 2/3] Created using Colab --- .../00_pytorch_fundamentals_exercises.ipynb | 439 ++++++++++++++++++ 1 file changed, 439 insertions(+) create mode 100644 extras/exercises/00_pytorch_fundamentals_exercises.ipynb diff --git a/extras/exercises/00_pytorch_fundamentals_exercises.ipynb b/extras/exercises/00_pytorch_fundamentals_exercises.ipynb new file mode 100644 index 0000000..0b24d6a --- /dev/null +++ b/extras/exercises/00_pytorch_fundamentals_exercises.ipynb @@ -0,0 +1,439 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "00_pytorch_fundamentals_exercises.ipynb", + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU" + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# 00. PyTorch Fundamentals Exercises\n", + "\n", + "### 1. Documentation reading\n", + "\n", + "A big part of deep learning (and learning to code in general) is getting familiar with the documentation of a certain framework you're using. We'll be using the PyTorch documentation a lot throughout the rest of this course. So I'd recommend spending 10-minutes reading the following (it's okay if you don't get some things for now, the focus is not yet full understanding, it's awareness):\n", + " * The documentation on [`torch.Tensor`](https://pytorch.org/docs/stable/tensors.html#torch-tensor).\n", + " * The documentation on [`torch.cuda`](https://pytorch.org/docs/master/notes/cuda.html#cuda-semantics).\n", + "\n" + ], + "metadata": { + "id": "AzDBM_v4iMe7" + } + }, + { + "cell_type": "code", + "source": [ + "# No code solution (reading)" + ], + "metadata": { + "id": "bGD0oD8Kizak" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "### 2. Create a random tensor with shape `(7, 7)`.\n" + ], + "metadata": { + "id": "__iXqqz-ioUJ" + } + }, + { + "cell_type": "code", + "source": [ + "# Import torch\n", + "import torch\n", + "\n", + "# Create random tensor\n", + "x = torch.rand(7,7)" + ], + "metadata": { + "id": "6pUq9Dc8i2L7", + "outputId": "b83566d4-04e4-45ae-b3f5-bb6b8bae6793", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 1, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "tensor([[0.8464, 0.0891, 0.0743, 0.5834, 0.2859, 0.7610, 0.0641],\n", + " [0.4562, 0.3367, 0.9342, 0.8983, 0.6533, 0.8893, 0.5817],\n", + " [0.6219, 0.6683, 0.4039, 0.3309, 0.0669, 0.9745, 0.5843],\n", + " [0.7627, 0.3354, 0.8490, 0.3607, 0.7142, 0.1134, 0.2614],\n", + " [0.2204, 0.6473, 0.5365, 0.5022, 0.1571, 0.8000, 0.0379],\n", + " [0.1687, 0.5905, 0.1027, 0.4813, 0.1817, 0.3850, 0.5294],\n", + " [0.8588, 0.0105, 0.2156, 0.0763, 0.3044, 0.0340, 0.9456]])" + ] + }, + "metadata": {}, + "execution_count": 1 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "### 3. Perform a matrix multiplication on the tensor from 2 with another random tensor with shape `(1, 7)` (hint: you may have to transpose the second tensor)." + ], + "metadata": { + "id": "9-XxvRLfiqkR" + } + }, + { + "cell_type": "code", + "source": [ + "# Create another random tensor\n", + "x = torch.rand(7,7)\n", + "y = torch.rand(1,7)\n", + "y = torch.transpose(y, 0, 1)\n", + "# Perform matrix multiplication\n", + "torch.matmul(x, y)" + ], + "metadata": { + "id": "NcLqR0Sbi_vT", + "outputId": "2d27ba57-24e4-4cbc-8675-ae8486741f44", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 20, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "tensor([[2.1758],\n", + " [2.7494],\n", + " [1.8747],\n", + " [2.3964],\n", + " [2.2742],\n", + " [1.5315],\n", + " [1.5614]])" + ] + }, + "metadata": {}, + "execution_count": 20 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "### 4. Set the random seed to `0` and do 2 & 3 over again.\n", + "\n", + "The output should be:\n", + "```\n", + "(tensor([[1.8542],\n", + " [1.9611],\n", + " [2.2884],\n", + " [3.0481],\n", + " [1.7067],\n", + " [2.5290],\n", + " [1.7989]]), torch.Size([7, 1]))\n", + "```" + ], + "metadata": { + "id": "eiutdKUFiryU" + } + }, + { + "cell_type": "code", + "source": [ + "# Set manual seed\n", + "RANDOM_SEED = 0\n", + "torch.manual_seed(RANDOM_SEED)\n", + "# Create two random tensors\n", + "x = torch.rand(7,7)\n", + "y = torch.rand(7,1)\n", + "# Matrix multiply tensors\n", + "torch.matmul(x, y)" + ], + "metadata": { + "id": "D-lOWI_1jRMm", + "outputId": "aecb8124-7395-44f4-e25f-c51287e04651", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 24, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "tensor([[1.8542],\n", + " [1.9611],\n", + " [2.2884],\n", + " [3.0481],\n", + " [1.7067],\n", + " [2.5290],\n", + " [1.7989]])" + ] + }, + "metadata": {}, + "execution_count": 24 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "### 5. Speaking of random seeds, we saw how to set it with `torch.manual_seed()` but is there a GPU equivalent? (hint: you'll need to look into the documentation for `torch.cuda` for this one)\n", + " * If there is, set the GPU random seed to `1234`." + ], + "metadata": { + "id": "ezY6ks9Cis37" + } + }, + { + "cell_type": "code", + "source": [ + "# Set random seed on the GPU\n", + "torch.cuda.manual_seed(1234)" + ], + "metadata": { + "id": "_LKWcfSTjp00" + }, + "execution_count": 25, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "\n", + "### 6. Create two random tensors of shape `(2, 3)` and send them both to the GPU (you'll need access to a GPU for this). Set `torch.manual_seed(1234)` when creating the tensors (this doesn't have to be the GPU random seed). The output should be something like:\n", + "\n", + "```\n", + "Device: cuda\n", + "(tensor([[0.0290, 0.4019, 0.2598],\n", + " [0.3666, 0.0583, 0.7006]], device='cuda:0'),\n", + " tensor([[0.0518, 0.4681, 0.6738],\n", + " [0.3315, 0.7837, 0.5631]], device='cuda:0'))\n", + "```" + ], + "metadata": { + "id": "Ir9qSaj6it4n" + } + }, + { + "cell_type": "code", + "source": [ + "# Set random seed\n", + "torch.manual_seed(1234)\n", + "\n", + "# Check for access to GPU\n", + "torch.cuda.is_available()\n", + "# Create two random tensors on GPU\n", + "x = torch.rand(2,3).to('cuda')\n", + "y = torch.rand(2,3).to('cuda')\n", + "x, y" + ], + "metadata": { + "id": "azXExiFZj5nm", + "outputId": "63d2a271-0359-44a5-f116-943c31443855", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 32, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "(tensor([[0.0290, 0.4019, 0.2598],\n", + " [0.3666, 0.0583, 0.7006]], device='cuda:0'),\n", + " tensor([[0.0518, 0.4681, 0.6738],\n", + " [0.3315, 0.7837, 0.5631]], device='cuda:0'))" + ] + }, + "metadata": {}, + "execution_count": 32 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "\n", + "### 7. Perform a matrix multiplication on the tensors you created in 6 (again, you may have to adjust the shapes of one of the tensors).\n", + "\n", + "The output should look like:\n", + "```\n", + "(tensor([[0.3647, 0.4709],\n", + " [0.5184, 0.5617]], device='cuda:0'), torch.Size([2, 2]))\n", + "```" + ], + "metadata": { + "id": "5TlAxeiSiu1y" + } + }, + { + "cell_type": "code", + "source": [ + "# Perform matmul on tensor_A and tensor_B\n", + "y = torch.transpose(y, 0, 1)\n", + "z = torch.matmul(x, y)" + ], + "metadata": { + "id": "fAeG7ox0lHEO" + }, + "execution_count": 37, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "### 8. Find the maximum and minimum values of the output of 7." + ], + "metadata": { + "id": "G7qfa5CSivwg" + } + }, + { + "cell_type": "code", + "source": [ + "# Find max\n", + "print(torch.max(z))\n", + "# Find min\n", + "print(torch.min(z))" + ], + "metadata": { + "id": "Fu8_3mZpllOd", + "outputId": "2300a237-bc1b-453c-ddab-6df21f90ebe5", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 40, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "tensor(0.5617, device='cuda:0')\n", + "tensor(0.3647, device='cuda:0')\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "### 9. Find the maximum and minimum index values of the output of 7." + ], + "metadata": { + "id": "wrTj5FgNiw47" + } + }, + { + "cell_type": "code", + "source": [ + "# Find arg max\n", + "print(torch.argmax(z))\n", + "\n", + "# Find arg min\n", + "print(torch.argmin(z))" + ], + "metadata": { + "id": "CCEKt4K2lsfQ", + "outputId": "8195dac8-7af1-4eb0-b64d-5a0df4970262", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 41, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "tensor(3, device='cuda:0')\n", + "tensor(0, device='cuda:0')\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "\n", + "### 10. Make a random tensor with shape `(1, 1, 1, 10)` and then create a new tensor with all the `1` dimensions removed to be left with a tensor of shape `(10)`. Set the seed to `7` when you create it and print out the first tensor and it's shape as well as the second tensor and it's shape.\n", + "\n", + "The output should look like:\n", + "\n", + "```\n", + "tensor([[[[0.5349, 0.1988, 0.6592, 0.6569, 0.2328, 0.4251, 0.2071, 0.6297,\n", + " 0.3653, 0.8513]]]]) torch.Size([1, 1, 1, 10])\n", + "tensor([0.5349, 0.1988, 0.6592, 0.6569, 0.2328, 0.4251, 0.2071, 0.6297, 0.3653,\n", + " 0.8513]) torch.Size([10])\n", + "```" + ], + "metadata": { + "id": "hmeybz4uixy7" + } + }, + { + "cell_type": "code", + "source": [ + "# Set seed\n", + "seed = 7\n", + "torch.manual_seed(seed)\n", + "# Create random tensor\n", + "x = torch.rand(1, 1, 1, 10)\n", + "print(x, x.shape)\n", + "# Remove single dimensions\n", + "x = torch.squeeze(x)\n", + "print(x,x.shape)\n", + "# Print out tensors and their shapes\n" + ], + "metadata": { + "id": "TQ9zbRzVl1jV", + "outputId": "b6478410-4347-48c6-c7f4-921e6d11e376", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 46, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "tensor([[[[0.5349, 0.1988, 0.6592, 0.6569, 0.2328, 0.4251, 0.2071, 0.6297,\n", + " 0.3653, 0.8513]]]]) torch.Size([1, 1, 1, 10])\n", + "tensor([0.5349, 0.1988, 0.6592, 0.6569, 0.2328, 0.4251, 0.2071, 0.6297, 0.3653,\n", + " 0.8513]) torch.Size([10])\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "Qys8ysUoNd0m" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file From a208d34719c688ef0e40a548310a4384db2ed665 Mon Sep 17 00:00:00 2001 From: Xilliano <106842023+Xilliano@users.noreply.github.com> Date: Sun, 3 Nov 2024 22:29:02 -0500 Subject: [PATCH 3/3] Delete extras/exercises directory --- .../00_pytorch_fundamentals_exercises.ipynb | 439 ------------------ 1 file changed, 439 deletions(-) delete mode 100644 extras/exercises/00_pytorch_fundamentals_exercises.ipynb diff --git a/extras/exercises/00_pytorch_fundamentals_exercises.ipynb b/extras/exercises/00_pytorch_fundamentals_exercises.ipynb deleted file mode 100644 index 0b24d6a..0000000 --- a/extras/exercises/00_pytorch_fundamentals_exercises.ipynb +++ /dev/null @@ -1,439 +0,0 @@ -{ - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "00_pytorch_fundamentals_exercises.ipynb", - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - }, - "accelerator": "GPU" - }, - "cells": [ - { - "cell_type": "markdown", - "source": [ - "# 00. PyTorch Fundamentals Exercises\n", - "\n", - "### 1. Documentation reading\n", - "\n", - "A big part of deep learning (and learning to code in general) is getting familiar with the documentation of a certain framework you're using. We'll be using the PyTorch documentation a lot throughout the rest of this course. So I'd recommend spending 10-minutes reading the following (it's okay if you don't get some things for now, the focus is not yet full understanding, it's awareness):\n", - " * The documentation on [`torch.Tensor`](https://pytorch.org/docs/stable/tensors.html#torch-tensor).\n", - " * The documentation on [`torch.cuda`](https://pytorch.org/docs/master/notes/cuda.html#cuda-semantics).\n", - "\n" - ], - "metadata": { - "id": "AzDBM_v4iMe7" - } - }, - { - "cell_type": "code", - "source": [ - "# No code solution (reading)" - ], - "metadata": { - "id": "bGD0oD8Kizak" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "### 2. Create a random tensor with shape `(7, 7)`.\n" - ], - "metadata": { - "id": "__iXqqz-ioUJ" - } - }, - { - "cell_type": "code", - "source": [ - "# Import torch\n", - "import torch\n", - "\n", - "# Create random tensor\n", - "x = torch.rand(7,7)" - ], - "metadata": { - "id": "6pUq9Dc8i2L7", - "outputId": "b83566d4-04e4-45ae-b3f5-bb6b8bae6793", - "colab": { - "base_uri": "https://localhost:8080/" - } - }, - "execution_count": 1, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - "tensor([[0.8464, 0.0891, 0.0743, 0.5834, 0.2859, 0.7610, 0.0641],\n", - " [0.4562, 0.3367, 0.9342, 0.8983, 0.6533, 0.8893, 0.5817],\n", - " [0.6219, 0.6683, 0.4039, 0.3309, 0.0669, 0.9745, 0.5843],\n", - " [0.7627, 0.3354, 0.8490, 0.3607, 0.7142, 0.1134, 0.2614],\n", - " [0.2204, 0.6473, 0.5365, 0.5022, 0.1571, 0.8000, 0.0379],\n", - " [0.1687, 0.5905, 0.1027, 0.4813, 0.1817, 0.3850, 0.5294],\n", - " [0.8588, 0.0105, 0.2156, 0.0763, 0.3044, 0.0340, 0.9456]])" - ] - }, - "metadata": {}, - "execution_count": 1 - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "### 3. Perform a matrix multiplication on the tensor from 2 with another random tensor with shape `(1, 7)` (hint: you may have to transpose the second tensor)." - ], - "metadata": { - "id": "9-XxvRLfiqkR" - } - }, - { - "cell_type": "code", - "source": [ - "# Create another random tensor\n", - "x = torch.rand(7,7)\n", - "y = torch.rand(1,7)\n", - "y = torch.transpose(y, 0, 1)\n", - "# Perform matrix multiplication\n", - "torch.matmul(x, y)" - ], - "metadata": { - "id": "NcLqR0Sbi_vT", - "outputId": "2d27ba57-24e4-4cbc-8675-ae8486741f44", - "colab": { - "base_uri": "https://localhost:8080/" - } - }, - "execution_count": 20, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - "tensor([[2.1758],\n", - " [2.7494],\n", - " [1.8747],\n", - " [2.3964],\n", - " [2.2742],\n", - " [1.5315],\n", - " [1.5614]])" - ] - }, - "metadata": {}, - "execution_count": 20 - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "### 4. Set the random seed to `0` and do 2 & 3 over again.\n", - "\n", - "The output should be:\n", - "```\n", - "(tensor([[1.8542],\n", - " [1.9611],\n", - " [2.2884],\n", - " [3.0481],\n", - " [1.7067],\n", - " [2.5290],\n", - " [1.7989]]), torch.Size([7, 1]))\n", - "```" - ], - "metadata": { - "id": "eiutdKUFiryU" - } - }, - { - "cell_type": "code", - "source": [ - "# Set manual seed\n", - "RANDOM_SEED = 0\n", - "torch.manual_seed(RANDOM_SEED)\n", - "# Create two random tensors\n", - "x = torch.rand(7,7)\n", - "y = torch.rand(7,1)\n", - "# Matrix multiply tensors\n", - "torch.matmul(x, y)" - ], - "metadata": { - "id": "D-lOWI_1jRMm", - "outputId": "aecb8124-7395-44f4-e25f-c51287e04651", - "colab": { - "base_uri": "https://localhost:8080/" - } - }, - "execution_count": 24, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - "tensor([[1.8542],\n", - " [1.9611],\n", - " [2.2884],\n", - " [3.0481],\n", - " [1.7067],\n", - " [2.5290],\n", - " [1.7989]])" - ] - }, - "metadata": {}, - "execution_count": 24 - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "### 5. Speaking of random seeds, we saw how to set it with `torch.manual_seed()` but is there a GPU equivalent? (hint: you'll need to look into the documentation for `torch.cuda` for this one)\n", - " * If there is, set the GPU random seed to `1234`." - ], - "metadata": { - "id": "ezY6ks9Cis37" - } - }, - { - "cell_type": "code", - "source": [ - "# Set random seed on the GPU\n", - "torch.cuda.manual_seed(1234)" - ], - "metadata": { - "id": "_LKWcfSTjp00" - }, - "execution_count": 25, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "\n", - "### 6. Create two random tensors of shape `(2, 3)` and send them both to the GPU (you'll need access to a GPU for this). Set `torch.manual_seed(1234)` when creating the tensors (this doesn't have to be the GPU random seed). The output should be something like:\n", - "\n", - "```\n", - "Device: cuda\n", - "(tensor([[0.0290, 0.4019, 0.2598],\n", - " [0.3666, 0.0583, 0.7006]], device='cuda:0'),\n", - " tensor([[0.0518, 0.4681, 0.6738],\n", - " [0.3315, 0.7837, 0.5631]], device='cuda:0'))\n", - "```" - ], - "metadata": { - "id": "Ir9qSaj6it4n" - } - }, - { - "cell_type": "code", - "source": [ - "# Set random seed\n", - "torch.manual_seed(1234)\n", - "\n", - "# Check for access to GPU\n", - "torch.cuda.is_available()\n", - "# Create two random tensors on GPU\n", - "x = torch.rand(2,3).to('cuda')\n", - "y = torch.rand(2,3).to('cuda')\n", - "x, y" - ], - "metadata": { - "id": "azXExiFZj5nm", - "outputId": "63d2a271-0359-44a5-f116-943c31443855", - "colab": { - "base_uri": "https://localhost:8080/" - } - }, - "execution_count": 32, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - "(tensor([[0.0290, 0.4019, 0.2598],\n", - " [0.3666, 0.0583, 0.7006]], device='cuda:0'),\n", - " tensor([[0.0518, 0.4681, 0.6738],\n", - " [0.3315, 0.7837, 0.5631]], device='cuda:0'))" - ] - }, - "metadata": {}, - "execution_count": 32 - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "\n", - "### 7. Perform a matrix multiplication on the tensors you created in 6 (again, you may have to adjust the shapes of one of the tensors).\n", - "\n", - "The output should look like:\n", - "```\n", - "(tensor([[0.3647, 0.4709],\n", - " [0.5184, 0.5617]], device='cuda:0'), torch.Size([2, 2]))\n", - "```" - ], - "metadata": { - "id": "5TlAxeiSiu1y" - } - }, - { - "cell_type": "code", - "source": [ - "# Perform matmul on tensor_A and tensor_B\n", - "y = torch.transpose(y, 0, 1)\n", - "z = torch.matmul(x, y)" - ], - "metadata": { - "id": "fAeG7ox0lHEO" - }, - "execution_count": 37, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "### 8. Find the maximum and minimum values of the output of 7." - ], - "metadata": { - "id": "G7qfa5CSivwg" - } - }, - { - "cell_type": "code", - "source": [ - "# Find max\n", - "print(torch.max(z))\n", - "# Find min\n", - "print(torch.min(z))" - ], - "metadata": { - "id": "Fu8_3mZpllOd", - "outputId": "2300a237-bc1b-453c-ddab-6df21f90ebe5", - "colab": { - "base_uri": "https://localhost:8080/" - } - }, - "execution_count": 40, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "tensor(0.5617, device='cuda:0')\n", - "tensor(0.3647, device='cuda:0')\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "### 9. Find the maximum and minimum index values of the output of 7." - ], - "metadata": { - "id": "wrTj5FgNiw47" - } - }, - { - "cell_type": "code", - "source": [ - "# Find arg max\n", - "print(torch.argmax(z))\n", - "\n", - "# Find arg min\n", - "print(torch.argmin(z))" - ], - "metadata": { - "id": "CCEKt4K2lsfQ", - "outputId": "8195dac8-7af1-4eb0-b64d-5a0df4970262", - "colab": { - "base_uri": "https://localhost:8080/" - } - }, - "execution_count": 41, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "tensor(3, device='cuda:0')\n", - "tensor(0, device='cuda:0')\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "\n", - "### 10. Make a random tensor with shape `(1, 1, 1, 10)` and then create a new tensor with all the `1` dimensions removed to be left with a tensor of shape `(10)`. Set the seed to `7` when you create it and print out the first tensor and it's shape as well as the second tensor and it's shape.\n", - "\n", - "The output should look like:\n", - "\n", - "```\n", - "tensor([[[[0.5349, 0.1988, 0.6592, 0.6569, 0.2328, 0.4251, 0.2071, 0.6297,\n", - " 0.3653, 0.8513]]]]) torch.Size([1, 1, 1, 10])\n", - "tensor([0.5349, 0.1988, 0.6592, 0.6569, 0.2328, 0.4251, 0.2071, 0.6297, 0.3653,\n", - " 0.8513]) torch.Size([10])\n", - "```" - ], - "metadata": { - "id": "hmeybz4uixy7" - } - }, - { - "cell_type": "code", - "source": [ - "# Set seed\n", - "seed = 7\n", - "torch.manual_seed(seed)\n", - "# Create random tensor\n", - "x = torch.rand(1, 1, 1, 10)\n", - "print(x, x.shape)\n", - "# Remove single dimensions\n", - "x = torch.squeeze(x)\n", - "print(x,x.shape)\n", - "# Print out tensors and their shapes\n" - ], - "metadata": { - "id": "TQ9zbRzVl1jV", - "outputId": "b6478410-4347-48c6-c7f4-921e6d11e376", - "colab": { - "base_uri": "https://localhost:8080/" - } - }, - "execution_count": 46, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "tensor([[[[0.5349, 0.1988, 0.6592, 0.6569, 0.2328, 0.4251, 0.2071, 0.6297,\n", - " 0.3653, 0.8513]]]]) torch.Size([1, 1, 1, 10])\n", - "tensor([0.5349, 0.1988, 0.6592, 0.6569, 0.2328, 0.4251, 0.2071, 0.6297, 0.3653,\n", - " 0.8513]) torch.Size([10])\n" - ] - } - ] - }, - { - "cell_type": "code", - "source": [], - "metadata": { - "id": "Qys8ysUoNd0m" - }, - "execution_count": null, - "outputs": [] - } - ] -} \ No newline at end of file