[ot-users] PythonFunction from a scalar output function

Julien Schueller schueller at phimeca.com
Wed Feb 1 14:13:00 CET 2017


Hello, 

No, that's not possible. OpenTURNS' functions return vectors anyway. 

If you absolutely have to reuse func as is you could still create a decorator that wraps your function and packs it in a list. 

j 

> De: "roy" <roy at cerfacs.fr>
> À: "users" <users at openturns.org>
> Envoyé: Mercredi 1 Février 2017 14:07:35
> Objet: [ot-users] PythonFunction from a scalar output function

> 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
> _______________________________________________
> OpenTURNS users mailing list
> users at openturns.org
> http://openturns.org/mailman/listinfo/users

-- 
Julien Schueller 
Phimeca Engineering 
www.phimeca.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://openturns.org/pipermail/users/attachments/20170201/f9b6ac0a/attachment.html>


More information about the users mailing list