4
$\begingroup$

I have the following two lists;

a = {-1.8, -1.6, -1.4, -1.2, -1., -0.7, -0.6, -0.4, -0.2, 0., 0.2, 0.4, 
    0.6, 0.8, 1., 1.2, 1.4, 1.6, 1.8}
b = {.2, .4, .6, .8, 1., 1.2, 1.4, 1.6, 1.8}

I want to turn this into coordinate points where each ai value is matched to each bi. Essentially (-1.8,.2),....,(-1.8,1.8) would be the first 9 points and it would create points for all 19 values of a.

$\endgroup$
1
  • 3
    $\begingroup$ Outer[List, a, b] // Flatten[#, 1] & $\endgroup$
    – Bob Hanlon
    Nov 25 '19 at 0:59
7
$\begingroup$

Perhaps Tuples[{a, b}]?

See Tuples.

$\endgroup$
2
  • 1
    $\begingroup$ Would have to Partition that if OP wanted 19 separate lists. $\endgroup$ Nov 25 '19 at 0:59
  • 1
    $\begingroup$ @RohitNamjoshi Yep, and we'd have to Flatten yours if the OP doesn't. $\endgroup$
    – Michael E2
    Nov 25 '19 at 1:05
3
$\begingroup$

You can also use Distribute:

Distribute[{a, b}, List]

and Thread

Join @@ (Thread[{#, b}] & /@ a)
$\endgroup$
1
$\begingroup$

Here is one way to do that

Transpose[{ConstantArray[#, 9], b}] & /@ a
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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