Mapping a function onto image volume

Is there an easy way to sample an analytical function in 3D space with Slicer? Say I want to represent a simple function like f(r) = exp(-r) as an image volume.

Thanks!

In case you didn’t already find it:

https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#Accessing_Volume_data_as_numpy_array