``````

In [2]:

from dynd import nd, ndt

``````
``````

In [3]:

@nd.functional.elwise
def f(x, y, z) -> ndt.float64:
return 2 * x + y - z

f

``````
``````

Out[3]:

nd.array(<callable at 0x1ed9dd0>,
type="(Dims... * Scalar, Dims... * Scalar, Dims... * Scalar) -> Dims... * float64")

``````
``````

In [4]:

f([0, 3, 5], 2.5, [5, 10, 15])

``````
``````

Out[4]:

nd.array([-2.5, -1.5, -2.5],
type="3 * float64")

``````
``````

In [3]:

@nd.functional.reduction
def f(x, y) -> ndt.int32:
return max(x, y)

f

``````
``````

Out[3]:

nd.array(<callable at 0x18172e0>,
type="(Dims... * Scalar, axes: ?Fixed * int32, identity: ?int32, keepdims: ?bool) -> Dims... * int32")

``````
``````

In [4]:

f([-5, 5, -3, 7, 2, -1])

``````
``````

Out[4]:

nd.array(7,
type="int32")

``````
``````

In [5]:

f([-5, 5, -3, 7, 2, -1], identity = 101)

``````
``````

Out[5]:

nd.array(101,
type="int32")

``````
``````

In [8]:

import math

@nd.functional.apply
def f_factorial(n: ndt.int32) -> ndt.int32:
return math.factorial(n - 1)

@nd.functional.apply
def f_gamma(x: ndt.float64) -> ndt.float64:
return math.gamma(x)

f = nd.functional.elwise(nd.functional.multidispatch(ndt.type('(Scalar) -> Scalar'), [f_factorial, f_gamma]))

f

``````
``````

Out[8]:

nd.array(<callable at 0x21046f0>,
type="(Dims... * Scalar) -> Dims... * Scalar")

``````
``````

In [9]:

f([5, 4, 3, 2, 1])

``````
``````

Out[9]:

nd.array([24,  6,  2,  1,  1],
type="5 * int32")

``````
``````

In [10]:

f([5.5, 4.5, 3.5, 2.5, 1.5])

``````
``````

Out[10]:

nd.array([ 52.3428,  11.6317,  3.32335,  1.32934, 0.886227],
type="5 * float64")

``````
``````

In [ ]:

``````