Numba - @vectorize

https://numba.readthedocs.io/en/stable/user/vectorize.html

https://numpy.org/doc/stable/reference/ufuncs.html

https://numpy.org/doc/stable/reference/generated/numpy.ufunc.reduce.html

https://numpy.org/doc/stable/reference/generated/numpy.ufunc.accumulate.html

INTRODUCTION

Numba’s @vectorize allows Python functions taking scalar input arguments to be used as NumPy 'ufuncs' (universal functions). NumPy ufuncs automatically get other features such as reduction, accumulation or broadcasting.


import numpy as np
from numba import vectorize, float64

@vectorize([float64(float64, float64)])   # a list of signatures is required
def f(x, y):
    return x + y

a = np.arange(6, dtype=np.float64)
print(f(1.2, 3.4))   # 4.6
print(f(a, a))   # [ 0.  2.  4.  6.  8. 10.]
print(f.reduce(a))   # 3.0
print(f.accumulate(a))   # [0.  0.2 0.6 1.2 2.  3. ]