Skip to content

Range(start, stop, step=1, bounds=Bounds.INCLUDED) Source

A regular sequence of numbers from start to stop, every step.

It selects positions in Region and creates values in Array.from_range. In a Region, start and step must be int, since a position is a whole number. Unlike the Python range, the end is included by default, as in Between.

Added in version 0.1.0

Parameters:

  • start (int | float)

    First number of the sequence.

  • stop (int | float)

    Last number of the sequence, reached only when it falls on a step.

  • step (int | float, default: 1)

    Gap between two numbers, 1 by default. A negative step goes downwards.

  • bounds (Bounds, default: Bounds.INCLUDED)

    Which of start and stop are part of the sequence. Both are included by default.

Raises:

  • InvalidTypeError

    When a setting is not of the type its annotation names.

  • InvalidStepError

    When step is zero, or goes away from stop, such as a step of 1 from 5 to 1.

Examples:

import numdaplot as ndp

ndp.Array.from_range(ndp.Range(start=0, stop=10, step=2))
# Array([ 0,  2,  4,  6,  8, 10], dtype=INT64)
scores = ndp.Array.from_list([10, 20, 30, 40])
scores.take(ndp.Region(rows=ndp.Range(start=1, stop=2)))
# Array([20, 30], dtype=INT64)

The first 3 rows, without counting the last position: stop is left out with Bounds.LOW_ONLY.

first_count = 3
first_rows = ndp.Range(start=0, stop=first_count, bounds=ndp.Bounds.LOW_ONLY)
scores.take(ndp.Region(rows=first_rows))
# Array([10, 20, 30], dtype=INT64)