Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform element-wise square root of a vector in Julia?

I need to perform the square root of an array in Julia but it seems sqrt() function just performs square roots on scalars and square matrices. Is there any simple compact way to do it without using loops?

like image 241
Nicholas Avatar asked Jan 25 '23 23:01

Nicholas


1 Answers

The documentation https://docs.julialang.org/en/v1/manual/arrays/#Array-and-Vectorized-Operators-and-Functions-1 tells you that to apply any function elementwise over an array, use the dot-broadcasting syntax:

sqrt.(x)
.√(x)
like image 65
Fredrik Bagge Avatar answered Mar 05 '23 08:03

Fredrik Bagge