From cf1885f47d6a2524dbcf99d1debd329c74622f92 Mon Sep 17 00:00:00 2001 From: RayonBiswas Date: Tue, 18 Feb 2025 20:34:36 +0530 Subject: [PATCH 1/2] now go! --- Tasks.ipynb | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 Tasks.ipynb diff --git a/Tasks.ipynb b/Tasks.ipynb new file mode 100644 index 0000000..cdfd54f --- /dev/null +++ b/Tasks.ipynb @@ -0,0 +1,222 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# **Task 1**\n", + "\n", + "Your goal is to find the answer of the dot product of the matrices of sizes (2,3), (3,5), (5,2) and (3,3).\n", + "\n", + "## **Workflow:**\n", + "1. Define the matrices of given sizes.\n", + "2. Print the matrices.\n", + "3. Use the np.dot function.\n", + "4. Print the output at each step.\n", + "5. Print the result.\n", + "\n", + "(Print the shape of matrix always with the matrix)\n" + ], + "metadata": { + "id": "6LkPygla_OXh" + } + }, + { + "cell_type": "code", + "source": [ + "# Import Numpy\n", + "import numpy as np" + ], + "metadata": { + "id": "Z8iSVv-r_WkT" + }, + "execution_count": 3, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Define the 4 matrices as A,B,C,D\n", + "A= np.random.randint(1, 10, size=(2, 3))\n", + "B= np.random.randint(1, 10, size=(3, 5))\n", + "C= np.random.randint(1, 10, size=(5, 2))\n", + "D= np.random.randint(1, 10, size=(3, 3))" + ], + "metadata": { + "id": "r1pVl7LbA1_I" + }, + "execution_count": 11, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Print the 4 matrices\n", + "print(A)\n", + "print(B)\n", + "print(C)\n", + "print(D)" + ], + "metadata": { + "id": "uJHj_CbhA83b", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "f4b9108c-aa46-4629-94d9-ee474dafe095" + }, + "execution_count": 12, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[2 7 3]\n", + " [2 7 4]]\n", + "[[7 6 3 2 7]\n", + " [9 8 2 5 3]\n", + " [8 2 6 2 8]]\n", + "[[9 1]\n", + " [2 7]\n", + " [7 1]\n", + " [3 5]\n", + " [3 6]]\n", + "[[9 9 6]\n", + " [2 3 9]\n", + " [4 7 5]]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "# Find the Dot Product of matrices\n", + "m = np.dot(A,B)\n", + "n = np.dot(B,C)\n", + "o = np.dot(A,D)\n", + "p= np.dot(C,D)" + ], + "metadata": { + "id": "MDcD7tOWBMzG", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 176 + }, + "outputId": "5200557b-efe2-4327-f944-9e973b9ce9f2" + }, + "execution_count": 16, + "outputs": [ + { + "output_type": "error", + "ename": "ValueError", + "evalue": "shapes (5,2) and (3,3) not aligned: 2 (dim 1) != 3 (dim 0)", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\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 3\u001b[0m \u001b[0mn\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mB\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mC\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mA\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mp\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mC\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mValueError\u001b[0m: shapes (5,2) and (3,3) not aligned: 2 (dim 1) != 3 (dim 0)" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "# ValueError: shapes (2,2) and (3,3) not aligned: 2 (dim 1) != 3 (dim 0)\n", + "\n", + "Now the task is to define a function named is_compatible() that takes 2 matrices as input and only allows the dot product if the condition number of **columns** in the first matrix (A) matches the number of **rows** in the second matrix (B).\n", + "\n", + "Print the ouput if condition is satisfied\n", + "Else print \"Dimension Error!!\"\n", + "\n", + "\n" + ], + "metadata": { + "id": "Rv1D09dyB0eP" + } + }, + { + "cell_type": "code", + "source": [ + "def is_compatible(A, B):\n", + " pass" + ], + "metadata": { + "id": "RmS0xS8tCjNC" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Find Dot product only if the matrices are compatible" + ], + "metadata": { + "id": "ds0XYSZ6E9nl" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# **Task 2**\n", + "\n", + "Your goal is to define a function that simulates a number-guessing game called \"Up-Down.\" The function, named up_down, should take an integer rounds as input, representing the number of turns the player gets.\n", + "\n", + "Game Rules:\n", + "\n", + "1. The player inputs a number between 1 and 12 for each round.\n", + "2. The computer randomly selects a number between 1 and 12.\n", + "3. The scoring system is as follows:\n", + " \n", + " a. If computer's guess is less than 7 and the player gains points equivalent to their guess if their guess is also less than 7, otherwise, they lose points equivalent to their guess.\n", + " \n", + " b. If computer's guess is exactly 7, the player gains 14 points if thier guess is 7, otherwise, they lose points equivalent to their guess.\n", + " \n", + " c. If computer's guess is greater than 7 and the player gains points equivalent to their guess if their guess is also greater than 7, otherwise, they lose points equivalent to their guess.\n", + "\n", + "4. The game continues until:\n", + "\n", + " a. The player reaches more than 30 points, they win.\n", + "\n", + " b. The player reaches less than -30 points, they lose.\n", + "\n", + " c. The maximum number of rounds is reached.\n", + " \n", + "At the end of the game, the function should print the final score.\n", + "\n", + "Your task is to implement this function in Python using the given rules." + ], + "metadata": { + "id": "SR_JeHeEdWOX" + } + }, + { + "cell_type": "code", + "source": [ + "def up_down(rounds):\n", + " pass" + ], + "metadata": { + "id": "0fxnUDma7aPx" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file From eaf96894da6d01266e1af175cbdef488ff17d38c Mon Sep 17 00:00:00 2001 From: RayonBiswas Date: Tue, 18 Feb 2025 20:44:41 +0530 Subject: [PATCH 2/2] task! --- Tasks.ipynb | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/Tasks.ipynb b/Tasks.ipynb index cdfd54f..344bf2b 100644 --- a/Tasks.ipynb +++ b/Tasks.ipynb @@ -104,33 +104,15 @@ "cell_type": "code", "source": [ "# Find the Dot Product of matrices\n", - "m = np.dot(A,B)\n", - "n = np.dot(B,C)\n", - "o = np.dot(A,D)\n", - "p= np.dot(C,D)" + "m = np.dot(A,D)\n", + "n = np.dot(m,B)\n", + "o = np.dot(n,C)" ], "metadata": { - "id": "MDcD7tOWBMzG", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 176 - }, - "outputId": "5200557b-efe2-4327-f944-9e973b9ce9f2" + "id": "MDcD7tOWBMzG" }, - "execution_count": 16, - "outputs": [ - { - "output_type": "error", - "ename": "ValueError", - "evalue": "shapes (5,2) and (3,3) not aligned: 2 (dim 1) != 3 (dim 0)", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\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 3\u001b[0m \u001b[0mn\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mB\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mC\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mA\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mp\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mC\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mValueError\u001b[0m: shapes (5,2) and (3,3) not aligned: 2 (dim 1) != 3 (dim 0)" - ] - } - ] + "execution_count": 17, + "outputs": [] }, { "cell_type": "markdown",