4

I have a table of dimension $M \times N \times Q$ of 3-tuples {x,y,z} that represent points, and another table of dimension $M \times N \times Q$ of scalar values. I am trying to join the two tables together to be of the form {{x,y,z}',n'} where {x,y,z}' and n' are the elements of each table at any given index.

Here is what I have so far, which generates the table of tuples and the table of scalar values

ot = ArrayReshape[Range[192], {4, 6, 8}];
x = Array[# &, 4, {-14, -7}];
y = Array[# &, 6, {225, 230}];
z = Array[# &, 8, {980, 1111}];
tup = ArrayReshape[Tuples[{z, y, x}], {4, 6, 8, 3}];

However, using Join[tup, ot] does not do the joining of the tables as I would expect, where ot and tup are joined elementwise.

mmal
  • 3,508
  • 2
  • 18
  • 38
QtizedQ
  • 185
  • 4

1 Answers1

6

J. M.'s suggestions should work fine, but a third option is MapThread, which I find a bit more intuitive and where the level specification is a bit less awkward:

MapThread[List, {tup, ot}, 3]

Without the third parameter, MapThread is used to apply a function to all pairs of elements at corresponding positions in two (or more) lists. With the third parameter, we push that process down to the third level, such that the function is applied to all pairs with the same (m,n,q) index, i.e. the corresponding vectors and scalars. The function we apply is simply List, which wraps both of them in a list.

Martin Ender
  • 8,774
  • 1
  • 34
  • 60