Re: Applying a function to a 2-D numarray

2005-05-16 Thread Robert Kern
Matt Feinstein wrote: > On Mon, 16 May 2005 12:03:24 -0600, Steven Bethard > <[EMAIL PROTECTED]> wrote: > >>Can you give an example of what you really want to do? Probably there >>are numarray functions that you can use. In general, you'll do better >>applying a sequence of numarray functions

Re: Applying a function to a 2-D numarray

2005-05-16 Thread Steven Bethard
Matt Feinstein wrote: > Well, for example, suppose I want to modify the elements of the matrix > in some fashion. However, I'm not entirely sure how I want to do it. > As a strawman, I generate a function with a Boolean test in it that > multiplies by one factor if the matrix element is in an inter

Re: Applying a function to a 2-D numarray

2005-05-16 Thread Matt Feinstein
On Mon, 16 May 2005 12:03:24 -0600, Steven Bethard <[EMAIL PROTECTED]> wrote: >Can you give an example of what you really want to do? Probably there >are numarray functions that you can use. In general, you'll do better >applying a sequence of numarray functions than operating element-wise on

Re: Applying a function to a 2-D numarray

2005-05-16 Thread Steven Bethard
Matt Feinstein wrote: > On Mon, 16 May 2005 11:07:06 -0600, Steven Bethard > <[EMAIL PROTECTED]> wrote: > > > >>I must be missing something, because the simplest possible thing seems >>to work for me: >> >>py> import numarray as na >>py> def plus1(arr): >>... return arr + 1 >>... >>py> def

Re: Applying a function to a 2-D numarray

2005-05-16 Thread Matt Feinstein
On Mon, 16 May 2005 11:07:06 -0600, Steven Bethard <[EMAIL PROTECTED]> wrote: > >I must be missing something, because the simplest possible thing seems >to work for me: > >py> import numarray as na >py> def plus1(arr): >... return arr + 1 >... >py> def apply_func(arr, f): >... return f(a

Re: Applying a function to a 2-D numarray

2005-05-16 Thread Steven Bethard
Matt Feinstein wrote: > Is there an optimal way to apply a function to the elements of a two-d > array? > > What I'd like to do is define some function: > > def plone(x): > return x+1 > > and then apply it elementwise to a 2-D numarray. I intend to treat the > function as a variable, so ufu

Applying a function to a 2-D numarray

2005-05-16 Thread Matt Feinstein
Is there an optimal way to apply a function to the elements of a two-d array? What I'd like to do is define some function: def plone(x): return x+1 and then apply it elementwise to a 2-D numarray. I intend to treat the function as a variable, so ufuncs are probably not appropriate-- I reali