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.

How can I create an one dimensional array (a vector) evaluating a function of two variables? I know how to do it with one variable:

Array[f, n, {a, b}] generates a list using n values from a to b.

share|improve this question

closed as too localized by belisarius, Oleksandr R., Yves Klett, m_goldberg, rm -rf Feb 19 '13 at 21:51

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Just Flatten it afterwards. –  Szabolcs Feb 19 '13 at 14:09
f @@@ Tuples[{Range[a, b, c], Range[d, e, f]}] might be close to what you're looking for. It is, however, 10% slower than @Szabolcs' suggestion and might use more RAM. –  whuber Feb 19 '13 at 21:51
add comment

1 Answer 1

You could use something akin to:

{ Array[f, {2, 2}, {a, b}, Sequence] }

(* {f[a, b], f[a, 1 + b], f[1 + a, b], f[1 + a, 1 + b]} *)

But I am not sure that this will be any more efficient that Flatten.

share|improve this answer
It very likely won't be because Flatten just needs to walk the expression tree once (actually just change the metadata about dimensions for packed arrays), while each Sequence needs to be flattened out step by step. But it's an interesting solution. –  Szabolcs Feb 19 '13 at 16:05
add comment

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