0

I have a list y={{a,b},{c,d},...} of dimension {10^5, 2}, and number x. I want to divide only the second part of each element of the list by x, and have as result a new list {{a,b/x},{c,d/x},...}. What is the fastest/best way to do it? This is what I have done:

{#[[1]], Divide[#[[2]], x]} & /@y

Thanks

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
sam84
  • 497
  • 6
  • 15

1 Answers1

2

If y is a packed array then Dot should be quite fast:

y = RandomReal[{0, 1}, {10^5, 2}];
x = 12.3;

result = y.{{1, 0}, {0, 1/x}};

This takes about a millisecond on my not-very-fast PC.

Simon Woods
  • 84,945
  • 8
  • 175
  • 324