Skip to content

Follow-ups from np.random → Generator API migration (rng scoping & docs) #552

@mmcky

Description

@mmcky

A few code-quality follow-ups noticed across the recent np.randomnumpy.random.Generator migration PRs (#538, #541, #544, #545, #547, #548, #549) — surfaced by Copilot during the corresponding translation-sync reviews in the Farsi target repo. Each is a small fix; grouping in one issue for convenience.

1. python_by_example.md — stale "three lines" wording

In the Random Draws section, the narrative says:

Returning to our program that plots white noise, the remaining three lines after the import statements are

But the snippet now has four lines (rng = np.random.default_rng() was added). Either update the count or include rng = ... in the snippet so the description matches.

2. functions.mdrng referenced in cells where it isn't defined

In Applications → Random sampling, several code cells call rng.standard_normal() / rng.uniform() but don't define rng in the same cell. If the reader runs the cell in isolation (or restarts the kernel), they get NameError: rng is not defined.

Suggested fix: either add rng = np.random.default_rng() to each affected cell, move the RNG setup to the shared imports cell at the top, or pass an RNG into generate_data() to avoid hidden cell-order dependencies.

3. scipy.md — same rng-scoping issue

The linregress example uses x = rng.standard_normal(200) / y = ... rng.standard_normal(200) without defining rng in the same cell/section. Same fix as above (define locally, or document the dependency).

4. numpy.mdDiscreteRV.__init__ docstring missing seed

DiscreteRV.__init__ now accepts a seed parameter and initializes self.rng:

def __init__(self, q, seed=None):
    \"\"\"
    The argument q is a NumPy array, or array like, nonnegative and sums
    to 1
    \"\"\"

The docstring only mentions q. Worth documenting what seed controls (and noting that seed=None yields non-reproducible draws).

5. (Bonus) about_py.md — inconsistent "Pytorch" vs "PyTorch"

The file uses both "PyTorch" and "Pytorch" in different paragraphs (and the line Pytorch is just one of several Python libraries for deep learning and AI. near line 142). Standardize on "PyTorch" everywhere.


Happy to send PRs for any/all of these — flagging here first so the team can decide scope/priority.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions