torch.clamp_(out, 0.0, 1.0) in Julia ?
I’m not familiar with PyTorch, but:
julia> clamp.(rand(10), 0.3, 0.7)
10-element Vector{Float64}:
0.7
0.3
0.7
0.3
0.4230237955951067
0.685909160414593
0.7
0.41101750524323943
0.4303566233748203
0.3
4 Likes
yes it works ! there is a dot… first time i wrote without dot it did not work
.
thank you !
This is fundamental in Julia, see:
https://docs.julialang.org/en/v1/manual/functions/#man-vectorized
clamp
operates on scalars:
julia> clamp(5, 0, 2)
2
so when you want to apply it elementwise to a vector of numbers, you either need to write a loop, or vectorize the function by using dot notation.
1 Like
you are right i should first learn Julia fundamentals, then translate python to julia