# Generate a list of points based on the y coordinate

I have a list of numbers corresponding to the known ordinates of some points:

x = {60, 101, 61, 203, 248, 346, 464,
635, 635, 958, 1019, 1020, 1182,
1276, 1397, 1607, 1710, 1869, 1975}


How can I generate a new list of points based on that one by adding an index, such as

P = {{1, 60}, {2, 101}, {3, 61}, ....}

• {Range[Length@x], x}\[Transpose] Commented Jun 20, 2020 at 10:15

This is most likely the most efficient approach:

Transpose[{Range[Length[x]], x}]

 {{1, 60}, {2, 101}, {3, 61}, {4, 203}, {5, 248}, {6, 346}, {7, 464}, {8, 635},
{9, 635}, {10, 958}, {11, 1019}, {12, 1020}, {13, 1182}, {14, 1276}, {15, 1397},
{16, 1607}, {17, 1710}, {18, 1869}, {19, 1975}}


Another approach (less efficient), that one could mention:

MapIndexed[ Flatten @ {#2, #1} &, x]


In a more general case instead of a strictly homogeneous distribution of the domain points we might deal with a random distribution which is still globally homogeneous, e.g.

y = RandomReal[{-1/2, 1/2}, #] + Range[#] & @ Length[x]

{ 1.01273, 1.6359, 3.38264, 4.08369, 5.05749, 6.12815, 7.35125, 7.93196,
8.97418, 10.2015, 10.824, 12.0907, 13.2303, 14.3775, 15.2711, 16.3996,
17.3865, 17.7342, 19.4849}


and then we generate the list simply with:

Transpose[{y, x}]

• How to load the abscissa from another list? Commented Jun 20, 2020 at 10:30
• There is no abscissa, you have to generate it with Range, yielding {1,2, ..., 19} Commented Jun 20, 2020 at 10:32
• @Mertin You can get it with MapIndexed as well as I demonstrated in the post. Commented Jun 20, 2020 at 10:38
• Also, Thread[{Range[Length[x]], x}] Commented Jun 20, 2020 at 15:02
• @BobHanlon, Good point, thanks! Although Transpose should be much faster than Thread, see e.g. Interlacing a single number into a long list where it is compared with Map and Tuples. Commented Jun 20, 2020 at 19:41

If you really want to have an easy solution:

ResourceFunction["AddIndices"][x]

P=Table[{k,x[[k]]},{k,1,Length[x]}]


For variety:

TimeSeries[x, {1}]["Path"]

{{1, 60}, {2, 101}, {3, 61}, {4, 203}, {5, 248}, {6, 346}, {7, 464},
{8, 635}, {9, 635}, {10, 958}, {11, 1019}, {12, 1020}, {13, 1182},
{14, 1276}, {15, 1397}, {16, 1607}, {17, 1710}, {18, 1869}, {19, 1975}}

TemporalData[x, {1}]["Path"]

{{1, 60}, {2, 101}, {3, 61}, {4, 203}, {5, 248}, {6, 346}, {7, 464},
{8, 635}, {9, 635}, {10, 958}, {11, 1019}, {12, 1020}, {13, 1182},
{14, 1276}, {15, 1397}, {16, 1607}, {17, 1710}, {18, 1869}, {19, 1975}}