Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an array of lists and want to correlate every list with each other like this:

Table[Table[Correlation[list[[y]], list[[x]]], {x, 1, Length[list]}], {y,1, Length[list]}];

I take the first list and correlate it with all others asf. I pretty much assume, this is not a very elegant and efficient code, so I wanted to ask for some alternatives. How would you guys do it?

share|improve this question
list = Permutations@Range@3; Correlation @@@ Subsets[list, {2}] ? – Dr. belisarius Jan 30 '14 at 17:29
Possibly related and/or helpful: – Mr.Wizard Jan 31 '14 at 6:51
up vote 4 down vote accepted

It's not entirely clear to me what you mean by "browse through an array" but from my best guess you might try:

array = RandomInteger[9, {50, 50}];

Pane[TableForm @ array, {500, 400}, Scrollbars -> True]

enter image description here

Since this is not the meaning you intended here is another:

list = {a, b, c, d};

Outer[f, list, list]
{{f[a, a], f[a, b], f[a, c], f[a, d]},
 {f[b, a], f[b, b], f[b, c], f[b, d]},
 {f[c, a], f[c, b], f[c, c], f[c, d]},
 {f[d, a], f[d, b], f[d, c], f[d, d]}}
f @@@ Tuples[list, 2]
 {f[a, a], f[a, b], f[a, c], f[a, d], f[b, a], f[b, b], f[b, c], f[b, d],
  f[c, a], f[c, b], f[c, c], f[c, d], f[d, a], f[d, b], f[d, c], f[d, d]}

Note that Outer produces a table of values (nested lists) while Tuples produces a flat list.

See also: how to efficiently apply function to all pairs of a set (and collect the results)

share|improve this answer
or ArrayPlot[array, ColorFunction -> "Rainbow"] for the more visual people out there :) – Pinguin Dirk Jan 30 '14 at 16:39
@PinguinDirk Of course that would be better for numeric data; this is intended as a generic method, where elements are arbitrary expressions. – Mr.Wizard Jan 30 '14 at 16:40
sure, just kidding - one can only guess what he wants, at this point – Pinguin Dirk Jan 30 '14 at 16:41
Sorry, don't know how to call it. I meant getting to every value of the array, e.g. for multiplying or correlating all values of an array with each other. – holistic Jan 30 '14 at 16:47
@Mr.Wizard I think he means "browse" as in the Scan sense... walk through the list. What OP wants is just Outer[Correlation, list, list] (possibly fix levels... didn't try), which is most likely a millionth duplicate. – R. M. Jan 30 '14 at 17:13

Another option might be to use TableView This gives the row number and column number on the sides as well. This is undocumented still as of Version 9.01, but it is there.

Mathematica graphics

array = RandomInteger[9, {50, 50}];

enter image description here

share|improve this answer
I see they've improved TableView since v7; looks nice. +1 – Mr.Wizard Jan 31 '14 at 6:52

I would do it like this:

Correlation @ Transpose @ list
share|improve this answer

Your Answer


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.