{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Drawing cards\n", "\n", "NOTE: In this notebook I use the `stats` sub-module of `scipy` for all statistics functions, including generation of random numbers. There are other modules with some overlapping functionality, e.g., the regular python random module, and the `scipy.random` module, but I do not use them here. The `stats` sub-module includes tools for a large number of distributions, it includes a large and growing set of statistical functions, and there is a unified class structure. (And namespace issues are minimized.) See https://docs.scipy.org/doc/scipy/reference/stats.html." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from scipy import stats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Intro\n", "\n", "For each of the draws, the probability of getting a heart is $\\frac{1}{4}$. The probability of getting $k$ successes in $n$ independent trials, where the $p$ is the probability of success in an indvidual trial is given by the binomial distribution `stats.binom.pmf(k,n,p)`:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The probability of 0 hearts is 0.17797851562500003\n", "The probability of 1 hearts is 0.3559570312500002\n", "The probability of 2 hearts is 0.29663085937500006\n", "The probability of 3 hearts is 0.13183593750000008\n", "The probability of 4 hearts is 0.032958984375\n", "The probability of 5 hearts is 0.004394531250000003\n", "The probability of 6 hearts is 0.00024414062500000016\n" ] } ], "source": [ "for k in range(7):\n", " n = 6\n", " p = 0.25\n", " print(\"The probability of\",k,\"hearts is\", stats.binom.pmf(k,n,p))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Version information\n", "`version_information` is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python for more information and instructions for package installation.\n", "\n", "`version_information` is installed on the linux network at Bucknell" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "%load_ext version_information" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.7.7 64bit [GCC 7.3.0]" }, { "module": "IPython", "version": "7.16.1" }, { "module": "OS", "version": "Linux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core" }, { "module": "scipy", "version": "1.5.2" }, { "module": "matplotlib", "version": "3.3.0" } ] }, "text/html": [ "
SoftwareVersion
Python3.7.7 64bit [GCC 7.3.0]
IPython7.16.1
OSLinux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core
scipy1.5.2
matplotlib3.3.0
Fri Aug 07 11:04:02 2020 EDT
" ], "text/latex": [ "\\begin{tabular}{|l|l|}\\hline\n", "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", "Python & 3.7.7 64bit [GCC 7.3.0] \\\\ \\hline\n", "IPython & 7.16.1 \\\\ \\hline\n", "OS & Linux 3.10.0 1062.9.1.el7.x86\\_64 x86\\_64 with centos 7.7.1908 Core \\\\ \\hline\n", "scipy & 1.5.2 \\\\ \\hline\n", "matplotlib & 3.3.0 \\\\ \\hline\n", "\\hline \\multicolumn{2}{|l|}{Fri Aug 07 11:04:02 2020 EDT} \\\\ \\hline\n", "\\end{tabular}\n" ], "text/plain": [ "Software versions\n", "Python 3.7.7 64bit [GCC 7.3.0]\n", "IPython 7.16.1\n", "OS Linux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core\n", "scipy 1.5.2\n", "matplotlib 3.3.0\n", "Fri Aug 07 11:04:02 2020 EDT" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "version_information scipy, matplotlib" ] }, { "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.7.7" } }, "nbformat": 4, "nbformat_minor": 2 }