{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "td115ZYDm2MH"
      },
      "source": [
        "# Numpy Documentaion: https://numpy.org/doc/stable/"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kmIR7LHSeKG8"
      },
      "source": [
        "# NumPy Indexing"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "18mjiYBdg7u8"
      },
      "outputs": [],
      "source": [
        "# Import Numpy\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "omb-sIHQeNyX"
      },
      "source": [
        "## Problem 1: Integer Indexing\n",
        "\n",
        "\n",
        "\n",
        "```\n",
        "arr = np.array([[10, 20, 30],\n",
        "                [40, 50, 60],\n",
        "                [70, 80, 90]])\n",
        "```\n",
        "\n",
        "- Use Integer indexing to retrieve the value '80'"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "o5OJGUkZeHCt"
      },
      "outputs": [],
      "source": [
        "# Integer index the array, 'arr'\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F2TrltyTelB5"
      },
      "source": [
        "## Problem 2: Indexing with an Array of Indices\n",
        "\n",
        "\n",
        "```\n",
        "arr = np.array([100, 200, 300, 400, 500])\n",
        "indices = np.array([0, 2, 4])\n",
        "```\n",
        "- Use your 'indices' array to extract elements from the array, 'arr'"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "id": "1iukbqdselIa"
      },
      "outputs": [],
      "source": [
        "# Index the array 'arr' using the array 'indices'\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mUs7PrfleXAm"
      },
      "source": [
        "## Problem 3: Boolean Indexing\n",
        "\n",
        "\n",
        "\n",
        "```\n",
        "arr = np.array([5, 15, 25, 35, 45])\n",
        "```\n",
        "\n",
        "- Use Boolean Indexing to extract all values from 'arr' which are greater than 20"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "gLKq-c_1eXG6"
      },
      "outputs": [],
      "source": [
        "# Generate your boolean array and assign it to the name, 'bool_arr'\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "HqOIb1gQiHIL"
      },
      "outputs": [],
      "source": [
        "# Use 'bool_arr' to index the original array 'arr'\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "veGr7dbEerQj"
      },
      "source": [
        "## Problem 4: Multi-dimensional Fancy Indexing\n",
        "\n",
        "- Generate a 3x3 array with random numbers in the range 1-100\n",
        "\n",
        "\n",
        "```\n",
        "rows = np.array([0, 1, 2])\n",
        "cols = np.array([2, 0, 1])\n",
        "```\n",
        "- Use the rows and cols array to extract the elements: (0,2), (1,0), and (2,1).\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "pZLIHmwmerWf"
      },
      "outputs": [],
      "source": [
        "# Generate your 2D array\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "of0X_7J8fMhl"
      },
      "outputs": [],
      "source": [
        "# Use Fancy Indexing to Extract elements : (0,2), (1,0), and (2,1)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "DdfF21DDjwEP"
      },
      "source": [
        "# Numpy Slicing"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "debZzVAlj0c4"
      },
      "source": [
        "## Problem 1: Basic 1D Slicing\n",
        "\n",
        "\n",
        "\n",
        "```\n",
        "arr = np.array([10, 20, 30, 40, 50, 60])\n",
        "```\n",
        "- Use slicing to extract [20, 30, 40] from the array 'arr'\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "xXlBFFZWj3mY"
      },
      "outputs": [],
      "source": [
        "# Slice the array 'arr'\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vHMxp3WEj4Qa"
      },
      "source": [
        "## Problem 2: 2D Row Slicing\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "```\n",
        "arr = np.array([[1, 2, 3],\n",
        "                [4, 5, 6],\n",
        "                [7, 8, 9],\n",
        "                [10, 11, 12]])\n",
        "```\n",
        "- Use slicing to extract the last two rows from arr\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "fco4Qxhaj4WO"
      },
      "outputs": [],
      "source": [
        "# Slice the array 'arr' to extract the last two rows\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0E-K-OSfj4d8"
      },
      "source": [
        "## Problem 3: 2D Column Slicing\n",
        "\n",
        "\n",
        "\n",
        "```\n",
        "arr = np.array([[100, 200, 300, 400],\n",
        "                [500, 600, 700, 800]])\n",
        "```\n",
        "- Use column slicing to extract only the middle two columns\n",
        "- Save your slice to a new array called, 'my_slice'\n",
        "- Use a numpy method to calculate the sum of all elements in your array, 'my_slice'\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "SGFu_p6Vj4jo"
      },
      "outputs": [],
      "source": [
        "# Extract the middle two columns from both rows in the array 'arr'\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "qF4O3ymOlG35"
      },
      "outputs": [],
      "source": [
        "# Calculate the sum of the elements in your array, 'my_slice'\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oyOTlnNIj4re"
      },
      "source": [
        "## Problem 5: Reverse Slicing\n",
        "\n",
        "\n",
        "\n",
        "```\n",
        "arr = np.array([5, 10, 15, 20, 25, 30])\n",
        "```\n",
        "- Use slicing to reverse the array, 'arr'\n",
        "- Save the reveresed array to the variable name, 'rev_arr'\n",
        "- Use Integer indexing to access index 2 of your array, 'rev_arr'\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "YB1oAoWpj4xl"
      },
      "outputs": [],
      "source": [
        "# Reverse the array, 'arr'\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "qCh6xyJsl254"
      },
      "outputs": [],
      "source": [
        "# Integer index your reversed array to access index 2\n"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "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.12.11"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
