Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 more shoter way to get that result? PS: maybe using of MapThread, but function Standarize take 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}}
share|improve this question

3 Answers 3

up vote 3 down vote accepted

How about this?

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
 ]
share|improve this answer
    
To generalize your approach just span to the end. data == Array[d, {5, 7}]; Standardize@data[[All, 1 ;;]] == Composition[Transpose, (Standardize /@ #) &, Transpose][data] True –  Bob Hanlon Jul 15 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 –  molekyla777 Jul 15 at 13:22
    
well, here you go then –  acl Jul 15 at 13:24

This should work

Thread[Standardize[data]]

Edit after the question was changed and comment from acl:

Standardize /@ Thread[data] // Transpose
share|improve this answer
    
+1 - of course! –  Chris Degnen Jul 15 at 13:13
2  
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 at 13:21
    
@acl corrected this. It's not elegant. –  Karsten 7. Jul 15 at 13:35
    
@Karsten7 neither is mine, it seems the real problem they had wasn't the mapping bit. –  acl Jul 15 at 16:32
data = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

Map[Standardize, data]

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

share|improve this answer
2  
He wanted to standarize over columns, not over rows! –  Artes Jul 15 at 13:06
1  
That's not what they asked for :) –  acl Jul 15 at 13:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.