{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c00bf530",
   "metadata": {},
   "source": [
    "# Homework 2 - Tools\n",
    "\n",
    "You will write code and discussion texts into code and text cells in this notebook. \n",
    "\n",
    "If a block starts with \\#TODO:, this means that you need to write something there. \n",
    "\n",
    "\n",
    "__Grading:__ The total points achievable are 10. You get 2 points for submission. Each subproblem gives you one point. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a440a191",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "691d1a9f",
   "metadata": {},
   "source": [
    "## P1: numpy array creation and printing\n",
    "\n",
    "* Create a python list implementing a 5x5 array, with each element having , filled in with x^2 + y^2. \n",
    "* Create from it the corresponding numpy array \"arr\"\n",
    "* Print the shape of the array (should be 5 by 5)\n",
    "* Print the type of the array (should be float64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4f94fcd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdb41036",
   "metadata": {},
   "source": [
    "## P2: array slicing and comparisons\n",
    "\n",
    "* Extract the second column from arr\n",
    "* Extract the second row from arr\n",
    "* Check whether they are equal and print accordingly \n",
    "* Create a new array arr2 which is a copy of the transpose of the original array.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2b3cf980",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement here\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ef0bbee",
   "metadata": {},
   "source": [
    "## P3: Using the random number generator \n",
    "* Create a random number generator in numpy.\n",
    "* Create a numpy array A of size 17 by 17 filled with zeros. \n",
    "* Fill the array with number drawn from a uniform distribution between 30.0 and 100.0\n",
    "* Print the array. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5f2e97b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a014f710",
   "metadata": {},
   "source": [
    "## P4: solving a system of linear equations with numpy\n",
    "* Consider a system of 17 linear equations. \n",
    "* The parameters of the unknowns are the same as the array A created above.\n",
    "* The left side of the equations is all 25.0 for each equation. Create a vector b for this. \n",
    "* Solve this system of equations using numpy.linalg.solve. Print out the solutions.\n",
    "* Solve the save system of equations, by taking the inverse of the A array and left multipying b with it. Print out the solutions. \n",
    "* Check if the solutions are identical and print \"Solutions are identical\" if they are and \"Solutions are not identical\" if they are not. Discuss it in form of comments in the code. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6bf4d2d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acd1cb25",
   "metadata": {},
   "source": [
    "## P5: create a pandas dataframe by reading a csv file\n",
    "* Read in the \"houses_Madrid.csv\" dataset which contains information about houses and apartments sold in Madrid, and create a pandas dataframe called \"df\"\n",
    "* Print out the number of rows in the dataframe\n",
    "* Print out the columns of the dataframe\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2b3f814f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db89d894",
   "metadata": {},
   "source": [
    "## P6: Selecting columns from a pandas dataframe and calculating values\n",
    "* Select the \"buy_price\" column from the dataframe. \n",
    "* Calculate the average buying price and print it out. \n",
    "* Calculate the maximum buying price and print it out."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "50bcbc63",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cff514e",
   "metadata": {},
   "source": [
    "## P7: Selecting rows from a pandas dataframe\n",
    "* Select the rows from df where the price was larger than one million and put it into a new dataframe df2\n",
    "* Print out how many houses were like this. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "02b9b261",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4e22835",
   "metadata": {},
   "source": [
    "## P8 - part 1: create a scatterplot in matplotlib\n",
    "* From the df dataset, select the \"sq_mt_built\" and \"buy_price\" columns\n",
    "* Convert them to numpy arrays.\n",
    "* Using the matplotlib.pyplot interface, create a scatterplot of the buying price (on the y axis) against the square meters area (on the x axis)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "848c94f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18d12178",
   "metadata": {},
   "source": [
    "## P8 - part 2: Create a line plot in matplotlib\n",
    "* Take the numpy array arr created in P1. \n",
    "* Plot its 2 and 3 rows using matplotlib pyplot. \n",
    "* The results should be two lines of different colors. The y axis is the values. The x axis is the indexes (0,1,2,...)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "25790648",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement here\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
