{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 1.1 \n",
    "\n",
    "Open this file (`ch1-exercises.ipynb`) in VS Code. \n",
    "\n",
    "Familiarise yourself with the VS Code editor. You can read https://code.visualstudio.com/docs/getstarted/userinterface alongside, or watch the YouTube video https://youtube.com/live/B5cZhBUpocQ.\n",
    "\n",
    "* On the left, you see a vertical bar (**Activity bar**) with several icons. Hover over the icons and click on them to see what they correspond to. For now, you will mainly need to learn about using Explorer, Search, and Extensions. Note that when you click repeatedly on an icon, you can make the Activity Bar disappear or bring them back. \n",
    "\n",
    "* Next the the Activity Bar is the **Explorer** (when selected), which lists all the folders files in the currently opened directory (also called workspace). Right click on a file or folder, or on the empty space to see what options pop up.\n",
    "\n",
    "* The biggest screen space is occupied by the **Editor**, which you use to edit your files and execute them. When a Jupyter Notebook is opened, watch out in particular for the horizontal buttons on the top showing ``+ Code`` ``+ Markdown`` ``>> Run All``\n",
    "\n",
    "* On the top you find the **Menu bar** (File, Edit, etc.) and next to it the **Search bar and command palette**. The command palette is accessed using Ctrl + Shift + P. Start typing and you'll see the available options. \n",
    "\n",
    "* Hitting Ctrl + J will toggle the bottom panel which shows the Output and Debug Console, as well the **Terminal** and **Jupyter tab**. The terminal is where you can access the command line to install Python packages, and the Jupyter tab lists the variables which are currently in memory. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 1.2\n",
    "\n",
    "Modify this markdown cell by double clicking on it. Here is an example of how to typeset a mathematical definition. \n",
    "\n",
    "**Definition:** The *nullspace* of a matrix $A\\in\\mathbb{C}^{m\\times n}$ is defined as the set of all vectors $x\\in\\mathbb{C}^n$ that satisfy $Ax = 0$. We denote this as\n",
    "$$\n",
    "    \\text{null}(A) := \\{ x\\in\\mathbb{C}^n\\, : \\, Ax = 0 \\}.\n",
    "$$\n",
    "\n",
    "Now extend this cell with your favourite mathematical theorem below. Use LaTeX notation with `$ ... $` and `$$ ... $$`. When done, hit Shift + Enter to see it displayed.\n",
    "\n",
    "**Theorem:** TODO"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 1.3\n",
    "\n",
    "Insert a code cell below that defines a function `mean` that takes as input a list or NumPy array $x$ and returns the mean of the entries. You can use this code snippet as a starting point:\n",
    "```\n",
    "import numpy as np\n",
    "\n",
    "def mean(x):\n",
    "    \"\"\"Returns the mean of the entries of x.\"\"\"\n",
    "    # TODO\n",
    "    return\n",
    "```\n",
    "\n",
    "**Notes:** \n",
    "\n",
    "* If you get an error *No module named 'numpy'*, you need to install the NumPy package. Open the terminal (Ctrl + J) and type `pip install numpy` (or if this fails, `python -m pip install numpy`). \n",
    "\n",
    "* If you have already created a virtual environment, double check that it is actually being used to run your Jupyter Notebooks. You should see a kernel indicating `.venv` in the top-right corner of the notebook. If this merely displays 'Python 3.xx.x' then click on it and select the .venv interpreter.\n",
    "\n",
    "* The default powershell terminal does not (always) display the virtual environment that it is using. This is a [known](https://stackoverflow.com/questions/52911573/powershell-does-not-show-the-virtualenv-id-or-name) problem. You can check whether or not you are using the virtual environment by typing in the terminal:\n",
    "\n",
    "   `pip -V`\n",
    "\n",
    "   If the path displayed there does not point to the `MAML\\.venv` folder, then you need to activate the .venv manually. This is done by typing\n",
    "\n",
    "   `.venv\\Scripts\\activate`\n",
    "\n",
    "   When working on Windows, the standard Command Prompt (cmd) does a better job. You can change your default terminal to the Command Prompt (cmd). Search for `Terminal: Select Default Profile` in the command palette."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.0\n",
      "2.0\n"
     ]
    }
   ],
   "source": [
    "# Testing\n",
    "print(mean([1, 7, -2])) # should print 2.0\n",
    "print(mean(np.array([1, 7, -2])))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 1.4\n",
    "\n",
    "Familiarise yourself with the Jupyter command bar shown on top of the editor window. Try out in particular the ``Run All``, ``Restart``, ``Clear All Outputs``, and ``Variables`` buttons. If you ever need to send a Jupyter Notebook to someone (e.g., as a coursework submission), it is strongly recommended to \n",
    "\n",
    "1. **Restart** the kernel in order to clear all variables in memory\n",
    "\n",
    "2. **Run All** cells to confirm that everything executes without errors"
   ]
  }
 ],
 "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.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
