# Elegant way to map a function over the columns of an array

I have an array

data = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};


And I want map Standardize over the column of the array. I use following code

Composition[
Transpose,
(Standardize /@ #)&,
Transpose][data]

{{-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}}


Is there a shorter way to get that result? PS: maybe using of MapThread, but function Standarize takes a list as input.

EDIT

I have picked a bad example. Use this example:

data = {{-4, -8, -8}, {-9, 4, 10}, {-3, -9, 0}}


The result I desire:

{{0.4147806779,-0.5068532453,-0.9609876522},{-1.140646864,1.151939194,1.034909779},{0.7258661863,-0.6450859486,-0.0739221271}}


Standardize@data


I'll assume you wanted something more general, so eg

MapThread[f, data]

(*{f[-4, -9, -3], f[-8, 4, -9], f[-8, 10, 0]}*)


Or if f only accepts a list as a parameter, why, wrap the arguments inside a list:

MapThread[
f[{##}] &,
data
]

• To generalize your approach just span to the end. data == Array[d, {5, 7}]; Standardize@data[[All, 1 ;;]] == Composition[Transpose, (Standardize /@ #) &, Transpose][data] True Jul 15, 2014 at 13:18
• This code MapThread[f, data] assume that function take several parameters. But function must take a List. But in particular Standardize@data You are right Jul 15, 2014 at 13:22
• well, here you go then
– acl
Jul 15, 2014 at 13:24

This should work

Thread[Standardize[data]]


Edit after the question was changed and comment from acl:

Standardize /@ Thread[data] // Transpose

• but don't they say they want to map f over the columns? and doesn't Thread[f[data]] map f over rows?
– acl
Jul 15, 2014 at 13:21
• @acl corrected this. It's not elegant. Jul 15, 2014 at 13:35
• @Karsten7 neither is mine, it seems the real problem they had wasn't the mapping bit.
– acl
Jul 15, 2014 at 16:32