Message Boards Message Boards

Compute the product between two sets

Posted 9 years ago


I'm new with Mathematica, and I search to write an expression that compute the product of two sets.

Table[f[x,y] , {x,S1},{y,S2} ] is nice to write, but as Cross function, it produce 2 parantheses levels rather than one.

{ { f[a,b], f[a,c] } , { f[z,b], f[z,c] } }

I expect to compute { f[a,b], f[a,c], f[z,b], f[z,c] }

Flatten didnt make things better, because f return List object as result.

Sure I dont know how to manipulate data, I really need to progress. Could someone help ?

Kind Regards,

4 Replies

I didnt know Flatten last optional parameter.

 Flatten[Outer[f, {a, b}, {c, z}], 1]

It's exactly what I need.

Thank you very much for your help.


  Flatten[Outer[f, {a, b}, {c, z}], 1]
POSTED BY: Ilian Gachevski

This is not what you want?

enter image description here

POSTED BY: Arnoud Buzing

Seems Tuples function provide help, but now, it's not really easy to read :

Table[ f [ x[[1]], x[[2]] ] , {x,Tuples[{S1,S2}]} ]

How could I have the same expression power than before with "local variables" associated to quantifiers/iterators ?

Kind Regards,

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract