{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Some random values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import random\n",
    "\n",
    "x_list  = [int(random.uniform(0, 1000)) for _ in range(0, 100)]\n",
    "count = len(x_list)\n",
    "\n",
    "print(f'{count} data values')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "q3 = np.percentile(x_list, 75)\n",
    "q1 = np.percentile(x_list, 25)\n",
    "\n",
    "print(f'q3 = {q3}')\n",
    "print(f'q1 = {q1}')\n",
    "print(f'q3 - q1 = {q3 - q1}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## stats.iqr function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy import stats\n",
    "\n",
    "stats_iqr = stats.iqr(x_list)\n",
    "print(f'stats.iqr(x_list) = {stats_iqr}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2-d array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 8 x 10 matrix\n",
    "matrix = np.array([[int(random.uniform(0, 25)) for _ in range(0, 10)]  # each row of 10\n",
    "                   for _ in range(0, 8)])                              # 8 rows\n",
    "\n",
    "matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "iqr_of_all  = stats.iqr(matrix)\n",
    "iqr_of_cols = stats.iqr(matrix, axis=0)\n",
    "iqr_of_rows = stats.iqr(matrix, axis=1)\n",
    "\n",
    "print(f'stats.iqr(matrix [all]           = {iqr_of_all}')\n",
    "print(f'stats.iqr(matrix, axis=0) [cols] = {iqr_of_cols}')\n",
    "print(f'stats.iqr(matrix, axis=1) [rows] = {iqr_of_rows}')"
   ]
  }
 ],
 "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.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
