1
$\begingroup$

Still trying to understand syntax for slots... How would I use slots to do this:

a = {
     {{1, 2, 3}, {4, 5, 6},    {7, 8, 9},    {10, 11, 12}},
     {{2, 4, 6}, {8, 10, 12},  {14, 16, 18}, {20, 22, 24}},
     {{3, 6, 9}, {12, 15, 18}, {21, 24, 27}, {30, 33, 36}}
    };

Show@ListPointPlot3D[Table[a[[i, j]], {i, {1, 2, 3}}, {j, {1, 2, 3, 4}}]]

enter image description here

I think it should look something like this:

 Show@ListPointPlot3D[a[[#1, #2]] & /@ {{1, 2, 3}, {1, 2, 3, 4}}]

but that gives several errors which I'm not interpreting correctly so am unable to fix it. Whereas I can see how this works:

Show@ListPointPlot3D[a[[#1]] & /@ {1, 2, 3}]
$\endgroup$
  • $\begingroup$ That's because Map doesn't construct the Tuples like Table does. You don't even need Slot or Map to do this, though, e.g. Show@ListPointPlot3D[Extract[a, Tuples[{{1, 2, 3}, {1, 2, 3, 4}}]]] $\endgroup$ – b3m2a1 Jan 30 at 19:28
  • 1
    $\begingroup$ I don't understand. With the a you define, Show@ListPointPlot3D[ Table[a[[i, j]], {i, {1, 2, 3}}, {j, {1, 2, 3, 4}}]] is the same as ListPointPlot3D[a], so you do not need slots or a table. $\endgroup$ – bill s Jan 30 at 19:41
  • $\begingroup$ I was trying to see how slots work as iterators, this probably isn't the best example though (as there is a lot of redundancy). Show@ListPointPlot3D[a[[#1]] & /@ {1, 2, 3}] works, but Show@ListPointPlot3D[a[[#1, #2]] & /@ {{1, 2, 3}, {1, 2, 3, 4}}] doesn't. I'll edit the question to show that's what I'm confused by $\endgroup$ – DrBubbles Jan 30 at 19:51
3
$\begingroup$

You could use Outer:

ListPointPlot3D[Outer[a[[##]] &, {1, 2, 3}, {1, 2, 3, 4}]]

For the specific example given you could also use ListPointPlot3D[Array[a[[##]] &, {3, 4}]].

Regarding ## see SlotSequence. If arguments are not neatly in order the longer form will work, here a[[#1, #2]] &.

$\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.