From d754f0ced438e046860493706d7b52bff8df7f13 Mon Sep 17 00:00:00 2001 From: James Weichert Date: Mon, 7 Aug 2023 11:51:02 -0700 Subject: [PATCH] Added np.random functions to cheatsheet --- cheatsheet.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cheatsheet.md b/cheatsheet.md index 97a8cfb..3ae11c0 100644 --- a/cheatsheet.md +++ b/cheatsheet.md @@ -51,7 +51,7 @@ _This cheat sheet has been modified from the Data 6 Python Reference and include | `tbl.plot(x_column, y_column)` or `tbl.plot(x_column)` | Draws a line plot consisting of one point for each row in `tbl`. If only `x_column` is specified, `plot` will plot the rest of the columns on the y-axis with different colored lines. | 1. **string**: name of the column on the x-axis
2. **string**: name of the column on the y-axis | None: draws a line graph | | `tbl.scatter(x_column, y_column)` | Draws a scatter plot consisting of one point for each row in `tbl`. | 1. **string**: x-axis column
2. **string**: y-axis column | None: draws a scatter plot | -### Table.where Predicates +### `Table.where` Predicates These functions can be passed in as the second argument to `tbl.where(..)` and act as a condition by which to select rows from `tbl`. | **Predicate** | **Description** | @@ -69,3 +69,9 @@ These functions can be passed in as the second argument to `tbl.where(..)` and a | `if :`
    ``
`elif :`
    ``
`else:`
    ``| Executes the code in `` only if `` evaluates to `True`. If `` is `False`, checks `` and executes code in `` if `True`. Otherwise, executes the code in `` | | `for in :`
    `` | Repeats code in `` for each `` in `` (array, string, etc.), assigning `` to each value in `` one at a time | | `while :`
    ``                                      | Repeats code in `` while `` is `True` | + +### `np.random` Functions +| **Function** | **Description** | **Input** | **Output** | +| `np.random.seed(seed)` | Selects one of `np.random`'s pre-generated 'random' sequences and starts at the beginning of the sequence. Each time the function is re-run it will restart the random numbers generated by `np.random.randint` at the beginning of the sequence corresponding to the given seed. | **int**: seed number | None | +| `np.random.randint(start, stop)` | Generates a random number between `start` (inclusive) and `stop` (exclusive) using a pre-generated sequence of random numbers (corresponding to the specified seed). | 1. **int**: minimum value that can be generated
2. **int**: the first value that _cannot_ be generated (upper endpoint) | **int**: a random number | +| `np.random.choice(choices)` | Selects one item at random from the array of choices. Each element in the array has an equal chance of being selected each time the function is called. | **array**: the choices of values to choose from | **int**, **string**, etc: the random selection |