Mapping functions of 2D numpy arrays

Posted by perimosocordiae on Stack Overflow See other posts from Stack Overflow or by perimosocordiae
Published on 2010-05-05T11:19:44Z Indexed on 2010/05/05 19:58 UTC
Read the original article Hit count: 372

Filed under:
|

I have a function foo that takes a NxM numpy array as an argument and returns a scalar value. I have a AxNxM numpy array data, over which I'd like to map foo to give me a resultant numpy array of length A.

Curently, I'm doing this:

result = numpy.array([foo(x) for x in data])

It works, but it seems like I'm not taking advantage of the numpy magic (and speed). Is there a better way?

I've looked at numpy.vectorize, and numpy.apply_along_axis, but neither works for a function of 2D arrays.

EDIT: I'm doing boosted regression on 24x24 image patches, so my AxNxM is something like 1000x24x24. What I called foo above applies a Haar-like feature to a patch (so, not terribly computationally intensive).

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy