Skip to main content

Bottleneck is a collection of fast NumPy array functions written in Cython.

Let’s give it a try. Create a NumPy array:

>>> import numpy as np
>>> arr = np.array([1, 2, np.nan, 4, 5])

Find the nanmean:

>>> import bottleneck as bn
>>> bn.nanmean(arr)
3.0

Moving window mean:

>>> bn.move_mean(arr, window=2, min_count=1)
array([ 1. ,  1.5,  2. ,  4. ,  4.5])

Benchmark

Bottleneck comes with a benchmark suite:

>>> bn.bench()
Bottleneck performance benchmark
    Bottleneck  1.0.0
    Numpy (np)  1.9.1
    Speed is NumPy time divided by Bottleneck time
    NaN means approx one-third NaNs; float64 and axis=-1 are used

                 no NaN     no NaN      NaN        NaN
                   (10,)   (1000,1000)   (10,)   (1000,1000)
    nansum         36.5        4.0       36.6        9.1
    nanmean       144.5        5.2      146.1        9.2
    nanstd        253.2        4.3      253.1        8.4
    nanvar        241.4        4.2      241.2        8.4
    nanmin         30.6        1.1       30.5        1.7
    nanmax         32.1        1.1       32.2        2.9
    median         43.3        0.8       45.7        0.9
    nanmedian      58.7        2.8       67.5        6.8
    ss             14.3        3.5       14.4        3.4
    nanargmin      60.8        4.1       61.1        7.3
    nanargmax      61.4        4.1       61.3        9.0
    anynan         12.9        1.0       13.5       89.2
    allnan         13.6       98.5       13.5       97.8
    rankdata       45.5        1.4       45.9        1.9
    nanrankdata    60.7       26.3       54.1       37.9
    partsort        6.4        0.9        6.5        1.1
    argpartsort     3.3        0.7        3.3        0.5
    replace         9.9        1.2        9.9        1.2
    move_sum      276.1      121.1      283.2      330.9
    move_mean     714.4       95.7      723.7      415.8
    move_std     1102.5       56.2     1160.7      749.0
    move_min      207.0       20.9      211.0       55.2
    move_max      213.8       21.4      218.4      118.6
    move_median   457.9       43.4      452.7      208.4

Only arrays with data type (dtype) int32, int64, float32, and float64 are accelerated. All other dtypes result in calls to slower, unaccelerated functions.

Where

download

http://pypi.python.org/pypi/Bottleneck

docs

http://berkeleyanalytics.com/bottleneck

code

http://github.com/kwgoodman/bottleneck

mailing list

http://groups.google.com/group/bottle-neck

License

Bottleneck is distributed under a Simplified BSD license. See the LICENSE file for details.

Install

Requirements:

Bottleneck

Python 2.7, 3.4; NumPy 1.9.1

Compile

gcc or clang or MinGW

Unit tests

nose

Optional:

tox, virtualenv

Run unit tests across multiple python/numpy versions

Cython

Development of bottleneck

To install Bottleneck on GNU/Linux, Mac OS X, et al.:

$ python setup.py build
$ sudo python setup.py install

To install bottleneck on Windows, first install MinGW and add it to your system path. Then install Bottleneck with the commands:

python setup.py build --compiler=mingw32
python setup.py install

Alternatively, you can use the Windows binaries created by Christoph Gohlke: http://www.lfd.uci.edu/~gohlke/pythonlibs/#bottleneck

Unit tests

After you have installed Bottleneck, run the suite of unit tests:

>>> import bottleneck as bn
>>> bn.test()
<snip>
Ran 79 tests in 70.712s
OK
<nose.result.TextTestResult run=79 errors=0 failures=0>

Metadata

Release files for Bottleneck 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Bottleneck 1.0.0
File Size Uploaded
Bottleneck-1.0.0.tar.gz 363.2 kB Details

Release files / Bottleneck-1.0.0.tar.gz

Download URL Bottleneck-1.0.0.tar.gz
Size 363.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8d9b7ad4fadf9648acc924a6ee522c7cb5b474e75faaad9d90dfd55e2805b495
BLAKE2b-256 checksum
How to use checksums
125c567d4b3b764013cd22451d0aeba4a9fc7dbde08f16752b808adae1aba776
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.5.0

43 release files

1.4.2

36 release files

1.4.1

36 release files

1.4.0

42 release files

1.3.8

43 release files

1.3.6

36 release files

1.3.4

16 release files

1.3.3

16 release files

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.0

1 release file

This release

1.0.0 This release

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page