[IPython-User] idiom or elegant way to fill array with function values

Jon Wilson jsw@fnal....
Mon Feb 10 11:59:14 CST 2014


Hi Christoph,
This question is probably more appropriately asked on the numpy mailing 
list.  You will get a swifter answer, and your question (and the answer) 
will be more easily found by others with the same question in the future.

http://www.scipy.org/scipylib/mailing-lists.html

In general, you first construct an array of the values on which you'd 
like the function to be evaluated.

input_values = linspace(-pi, pi, 100)

Then, you call your function on the array, if it is a ufunc.

output_values = sin(input_values)

You can turn a regular function into a ufunc using vectorize, which you 
can use as a function decorator.

Again, please re-ask on the numpy list.  My answer above is rather 
simplistic and likely incomplete.  The real numpy experts are there.
Regards,
Jon

On 02/10/2014 03:06 AM, Krischu wrote:
> I'm seeking for away to fill an array more or less elegantly with values:
>
>
> lambda expression perhaps? I just found numpy.fromfunction
>
> --
> Christoph
>
>
>
>
> --
> View this message in context: http://python.6.x6.nabble.com/idiom-or-elegant-way-to-fill-array-with-function-values-tp5046877.html
> Sent from the IPython - User mailing list archive at Nabble.com.
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>



More information about the IPython-User mailing list