Skip to content

Commit

Permalink
Added np.random functions to cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
james-weichert committed Aug 7, 2023
1 parent 9da94ef commit d754f0c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br> 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 <br> 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** |
Expand All @@ -69,3 +69,9 @@ These functions can be passed in as the second argument to `tbl.where(..)` and a
| `if <if expression>:` <br> &nbsp;&nbsp;&nbsp;&nbsp;`<if body>` <br> `elif <elif expression>:` <br> &nbsp;&nbsp;&nbsp;&nbsp;`<elif body>` <br> `else:` <br> &nbsp;&nbsp;&nbsp;&nbsp;`<else body>`| Executes the code in `<if body>` only if `<if expression>` evaluates to `True`. If `<if expression>` is `False`, checks `<elif expression>` and executes code in `<elif body>` if `True`. Otherwise, executes the code in `<else body>` |
| `for <element> in <sequence>:` <br> &nbsp;&nbsp;&nbsp;&nbsp;`<for body>` | Repeats code in `<for body>` for each `<element>` in `<sequence>` (array, string, etc.), assigning `<element>` to each value in `<sequence>` one at a time |
| `while <boolean expression>:` <br> &nbsp;&nbsp;&nbsp;&nbsp;`<while_body>`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Repeats code in `<while body>` while `<boolean expression>` 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 <br> 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 |

0 comments on commit d754f0c

Please sign in to comment.