1

Say that I have a list of the form

A={1,2,{{3,4},{5,6}}}

I want to manipulate the first elements of the last sublist. For example, in the case of multiplication by two, the resulting matrix should become

B={1,2,{{6,4},{10,6}}}

In my case, the third sublist contains around 40,000 pairs of numbers. If possible, I would like to avoid iterating through each data point. Any help would be greatly appreciated.

Eric
  • 91
  • 2

1 Answers1

3

You can use Map. Suppose f is the function you want to apply to the latter part of the list:

a = {1, 2, {{3, 4}, {5, 6}}};
Map[f, a, {2}]
{1, 2, {f[{3, 4}], f[{5, 6}]}}

For your particular f (multiplication by 2)

f[{x_, y_}] := {2 x, y};
Map[f, a, {2}]
{1, 2, {{6, 4}, {10, 6}}}
bill s
  • 68,936
  • 4
  • 101
  • 191