Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

# array_ module

Utilities for working with arrays.

## build_nan_mask function

    build_nan_mask(
        *arrs
    )

Build a NaN mask out of one to multiple arrays via the OR rule.

## cast_to_max_precision function

    cast_to_max_precision(
        arr,
        max_precision,
        float_only=True,
        check_bounds=True,
        strict=True
    )

Cast an array to a maximum integer/floating precision.

Argument must be either an integer denoting the number of bits, or one of 'half', 'single', and 'double'.

## cast_to_min_precision function

    cast_to_min_precision(
        arr,
        min_precision,
        float_only=True
    )

Cast an array to a minimum integer/floating precision.

Argument must be either an integer denoting the number of bits, or one of 'half', 'single', and 'double'.

## get_ranges_arr function

    get_ranges_arr(
        starts,
        ends
    )

Build array from start and end indices.

Based on https://stackoverflow.com/a/37626057

## hash_int_rows_nb function

    hash_int_rows_nb(
        arr
    )

Hash rows in a 2-dim array.

First digits of each hash correspond to the left-most column, the last digits to the right-most column. Thus, the resulting hashes are not suitable for sorting by value.

## index_repeating_rows_nb function

    index_repeating_rows_nb(
        arr
    )

Index repeating rows using monotonically increasing numbers.

## insert_argsort_nb function

    insert_argsort_nb(
        A,
        I
    )

Perform argsort using insertion sort.

In-memory and without recursion -> very fast for smaller arrays.

## int_digit_count_nb function

    int_digit_count_nb(
        number
    )

Get the digit count in a number.

## is_range function

    is_range(
        arr
    )

Checks if array is arr range.

## is_range_nb function

    is_range_nb(
        arr
    )

Numba-compiled version of is_range().

## is_sorted function

    is_sorted(
        arr
    )

Checks if array is sorted.

## is_sorted_nb function

    is_sorted_nb(
        arr
    )

Numba-compiled version of is_sorted().

## max_count_nb function

    max_count_nb(
        arr
    )

Get the first position, the value, and the count of the array's maximum.

## max_rel_rescale function

    max_rel_rescale(
        arr,
        to_range
    )

Rescale elements in `arr` relatively to maximum.

## min_count_nb function

    min_count_nb(
        arr
    )

Get the first position, the value, and the count of the array's minimum.

## min_rel_rescale function

    min_rel_rescale(
        arr,
        to_range
    )

Rescale elements in `arr` relatively to minimum.

## rescale function

    rescale(
        arr,
        from_range,
        to_range
    )

Renormalize `arr` from one range to another.

## rescale_float_to_int_nb function

    rescale_float_to_int_nb(
        floats,
        int_range,
        total
    )

Rescale a float array into an int array.

## rescale_nb function

    rescale_nb(
        arr,
        from_range,
        to_range
    )

Numba-compiled version of rescale().

## squeeze_nan function

    squeeze_nan(
        *arrs,
        nan_mask=None
    )

Squeeze NaN values using a mask.

## uniform_summing_to_one_nb function

    uniform_summing_to_one_nb(
        n
    )

Generate random floats summing to one.

See # https://stackoverflow.com/a/2640067/8141780

## unsqueeze_nan function

    unsqueeze_nan(
        *arrs,
        nan_mask=None
    )

Un-squeeze NaN values using a mask.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings