Bottleneck

1.6.0 · active · verified Thu Apr 09

Bottleneck is a Python library that provides a collection of fast, C-optimized functions for NumPy arrays, particularly useful for operations involving NaNs (Not a Number). It aims to offer significant performance improvements over equivalent NumPy functions for large arrays by implementing them in C. The current version is 1.6.0, with releases generally following significant NumPy updates or critical bug fixes, ensuring compatibility and performance.

Warnings

Install

Imports

Quickstart

This example demonstrates how to import bottleneck as 'bn' and use its NaN-aware functions, such as `nansum` and `nanmean`, on NumPy arrays for potentially faster computation.

import numpy as np
import bottleneck as bn

a = np.array([1.0, 2.0, np.nan, 4.0])
b = np.arange(12.0).reshape(3, 4)
b[0, 0] = np.nan

print(f"Original array a: {a}")
print(f"bn.nansum(a): {bn.nansum(a)}")

print(f"\nOriginal array b:\n{b}")
print(f"bn.nanmean(b, axis=1): {bn.nanmean(b, axis=1)}")

view raw JSON →