{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Module 9-1: Quick review questions\n", "\n", "---\n", "\n", "\n", "\n", "This notebook is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/)." ] }, { "cell_type": "markdown", "metadata": { "cell_style": "center", "slideshow": { "slide_type": "slide" } }, "source": [ "## Load packages" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cell_style": "center", "slideshow": { "cell_style": "split", "slide_type": "-" } }, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "from pathlib import Path\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import seaborn as sns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Quick Review Question 1**\n", "\n", "1. Generate a single random floating point number between 10 and 100. \n", "2. Generate a length-5 vector of random numbers between -3 and 3.\n", "3. Generate a 2-by-4 matrix of random numbers between 8 and 12." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Quick Review Question 2**\n", "\n", "Use both the floor method and the direct generation of random integers for each exercise below.\n", "\n", "1. Give the command to generate a number representing a random throw of a die with a return value of 1, 2, 3, 4, 5, or 6.\n", "2. Give the command to generate 20 random numbers representing ages from 18 to 22, inclusively, that is, random integers from the set {18, 19, 20, 21, 22}." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Quick Review Question 3**\n", "\n", "1. Write a command to generate a 10-by-10 matrix of random integers from 1 through 100, inclusively, that is, from the set {1, 2, 3, ..., 99, 100}. Print out several matrices below to show how it changes each time.\n", "\n", "2. Now seed the random number generator with a four-digit number and print out 4 matrices. Then rerun it (make sure the seed is also rerun!) several times, and notice that the list does not change." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Quick Review Question 4**\n", "\n", "Assign 10 to the variable `r`.\n", "Then, assign to `r` the remainder of the division of `7r` by `11`. \n", "Before executing the command, calculate the final value of `r` by hand to check your work." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Quick Review Question 5**\n", "\n", "1. Generate 10,000 normally distributed random numbers using the function `np.random.uniform` using the parameter `size` in the same manner as `np.random.uniform`. Store the results in the variable `normal_nums`. **Do not display `normal_nums`**!\n", "2. Determine the mean of `normal_nums`.\n", "3. Determine the standard deviation of `normal_nums`.\n", "4. In a normal distribution, the mean is 0 and the standard deviation is 1. Are your answers from Parts b and c approximately equal to these values?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Quick Review Question 6**\n", "\n", "1. Generate an array, `sine_array`, of 1000 values of the sine of a random floating point number between 0 and \\\\(\\pi\\\\).\n", "2.\tDisplay a histogram of `sine_array`.\n", "3.\tDisplay a histogram of `sine_array` with 10 categories.\n", "4.\tGive the interval for the last category.\n", "5.\tApproximate the number of values in this category." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }