On Sun, Oct 07, 2007 at 06:52:11AM -0400, Neal Becker wrote:
> Suppose I have a function F(), which is defined for 1-dim arguments. If the
> user passes an n>1 dim array, I want to apply F to each 1-dim view.
>
> For example, for a 2-d array, apply F to each row and return a 2-d result.
>
> For a 3-d array, select each 2-d subarray and see above. Return 3-d result.
>
> Any suggestions on how to code something like this in numpy?
Not the most efficient way, but easy to read and understand:
import numpy as N
def func(a):
return a.shape
z = N.zeros((2,2,2,2))
print N.array([func(sub) for sub in z])
Regards
Stéfan
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion