Function to obtain the maximum value of each element of an array with a second argument of zero?

In Julia, max is for comparison of two elements and maximum is for the highest value in an iterable. Here, you want comparison between two elements to be broadcasted over every value of your array, so you can do it as follows:

julia> a = rand(10)
10-element Vector{Float64}:
 0.22992278012202094
 0.2474774269332295
 0.027469463935002603
 0.2212289112594984
 0.6776369063933763
 0.560465219340989
 0.7627282729774861
 0.33638924323772235
 0.8933858558943317
 0.5810967639065461

julia> max.(a, 0.5)
10-element Vector{Float64}:
 0.5
 0.5
 0.5
 0.5
 0.6776369063933763
 0.560465219340989
 0.7627282729774861
 0.5
 0.8933858558943317
 0.5810967639065461
3 Likes