JuliaLang/julia — pull request #494 by dcjones (2012-02-29 19:08:24+00:00)
Title: An R-like apply function

To facilitate discussion, here's my first pass at a function to map another function across an axis of an array, as per Issue #492.

This is comparable to the `apply` function in R, or the `apply_along_axis` function in numpy, letting you do things like `amap(sum, x, 1)` to sum the columns of a matrix, for example.

One thing to consider is whether a special case should be added if the function being applied returns an array of the same size it was applied to. With this version, `amap(identity, x, 1)` will return an array of arrays, when applied to a matrix `x`, rather than a reproducing `x`.

Both the numpy and R function do have this special case, but it slightly complicates the semantics, so I'm ambivalent. You can do this now (sub-optimally, perhaps) with `apply(hcat, amap(identity, x, 1))`.

Of course any suggestions for a better name than `amap` are welcomed. The numpy `apply_along_axis` seems a little verbose, and the R `apply` conflicts with an existing function.