[ot-users] PythonFunction from a scalar output function

roy roy at cerfacs.fr
Wed Feb 1 14:07:35 CET 2017


Hi,

Is it possible to create a PythonFunction without the function returning a list?

This does not work:

def func(x):
    f = 0.
    for i in range(2):
        f += np.sin(x[i]) * np.sin((i + 1) * x[i]** 2 / np.pi) ** (2 * 10)

    return -f

f = ot.PythonFunction(2, 1, func)


This works:

def func(x):
    f = 0.
    for i in range(2):
        f += np.sin(x[i]) * np.sin((i + 1) * x[i]** 2 / np.pi) ** (2 * 10)

    return [-f]

f = ot.PythonFunction(2, 1, nunc)

Thanks,

Pamphile ROY


More information about the users mailing list