3

Given a one dimensional vector in Julia with positive and negative entries, like A=[1;-3;5;-7], is there any function or command that can alter this vector so that its elements all become positive, so that it becomes A=[1;3;5;7]?

James Rider
  • 633
  • 1
  • 9
  • Have a look at: [Julia - absolute value of an array](https://stackoverflow.com/q/53943507/10488504) – GKi Jul 16 '22 at 20:03
  • Does this answer your question? [Julia - absolute value of an array](https://stackoverflow.com/questions/53943507/julia-absolute-value-of-an-array) – Antonello Jul 16 '22 at 21:25

1 Answers1

3

Vectorize over abs:

julia> abs.(A)
4-element Vector{Int64}:
 1
 3
 5
 7

Any function in Julia can work over an array by just appending a dot . to its name.

Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62