I'm not sure what you mean by large lists since any solution is reasonable fast on a list which I think is pretty large. Please find the 2 solutions mentioned by Olek and Sjoerd and a compiled one below
normTed[coordinates_] := Norm /@ coordinates;
normSjoerd = Function[coords, Sqrt@Total[coords coords, {2}]];
normOlek = Function[coords, Sqrt@Total[Internal`Square[coords], {2}]];
normPatrick = Compile[{{v, _Real, 1}}, Sqrt[v.v], CompilationTarget -> "C",
RuntimeAttributes -> {Listable}, Parallelization -> True];
data = RandomReal[{0, 1}, {10^8, 2}];
First[AbsoluteTiming[#[data]]] & /@ {normTed, normSjoerd, normOlek, normPatrick}
(*
{9.800536, 5.647508, 5.384156, 4.350411}
*)
As you can see from top to bottom: Readability drops, performance rises. Whether the 5 seconds are really worth the effort is questionable. Maybe you can update your question with information about your real data.
Btw, on my machine the compiled version of Sqrt[v.v]
is a glimpse faster (.102s) than the compiled version with Norm[v]
. Therefore, I did not use Norm
but it is of course compilable as J.M. pointed out.
listableNorm = Function[coords, Sqrt@Total[Internal`Square[coords], {2}]];
. $\endgroup$Norm[]
is in this list, though. $\endgroup$listableNorm2 = Function[coords, Sqrt@Total[coords coords, {2}]]
it's not significantly slower than usingInternal`Square
(tested usingLocationEquivalenceTest
with 100 timings of 10^6 vectors), but you don't have to use an undocumented function, which generally is scary. $\endgroup$