Git Product home page Git Product logo

numpy_ext's Introduction

add support for numpy==1.25

NumPy Extensions

Build Status - GitHub Build Status - GitHub Deploy PYPI Coverage Status

An extension library for NumPy that implements common array operations not present in NumPy.

  • npext.fill_na(...)
  • npext.drop_na(...)
  • npext.rolling(...)
  • npext.expanding(...)
  • npext.rolling_apply(...)
  • npext.expanding_apply(...)
  • # etc

Documentation

Installation

Regular installation:

pip install numpy_ext

For development:

git clone https://github.com/3jane/numpy_ext.git
cd numpy_ext
pip install -e .[dev]  # note: make sure you are using pip>=20

Examples

Here are few common examples of how the library is used. The rest is available in the documentation.

  1. Apply a function to a rolling window over the provided array
import numpy as np
import numpy_ext as npext

a = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
window = 3

npext.rolling_apply(np.sum, window, a)

> array([nan, nan,  3.,  6.,  9., 12., 15., 18., 21., 24.])
  1. Same as the above, but with a custom function, two input arrays and parallel computation using joblib:
def func(array_first, array_second, param):
    return (np.min(array_first) + np.sum(array_second)) * param


a = np.array([0, 1, 2, 3])
b = np.array([3, 2, 1, 0])

npext.rolling_apply(func, 2, a, b, n_jobs=2, param=-1)

> array([nan, -5., -4., -3.])
  1. Same as the first example, but using rolling function:
a = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
window = 3

rolls = npext.rolling(a, window, as_array=True)

np.sum(rolls, axis=1)

> array([nan, nan,  3.,  6.,  9., 12., 15., 18., 21., 24.])
  1. Apply a function with multiple output to a rolling window over the provided array, with no nans prepend
res = npext.rolling_apply(
        lambda x: (max(x), min(x)),
        3,
        np.array([1, 2, 5, 1, 6, 4, 0]),
        prepend_nans=False,
    )

> array([[5, 1],
       [5, 1],
       [6, 1],
       [6, 1],
       [6, 0]])

License

MIT Licence

The software is distributed under MIT license.

numpy_ext's People

Contributors

saninstein avatar cutebomb avatar emiliobasualdo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.