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

**URL:** <https://discourse.julialang.org/t/function-to-obtain-the-maximum-value-of-each-element-of-an-array-with-a-second-argument-of-zero/120852>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 3, 2024, 11:17am UTC](https://discourse.julialang.org/t/function-to-obtain-the-maximum-value-of-each-element-of-an-array-with-a-second-argument-of-zero/120852 "2024-10-03T11:17:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)\
**Post date:** [October 3, 2024, 11:17am UTC](https://discourse.julialang.org/t/function-to-obtain-the-maximum-value-of-each-element-of-an-array-with-a-second-argument-of-zero/120852/1 "2024-10-03T11:17:04Z")

</div>

Is there a function in Julia which takes an array and a scalar as input and returns an array as output where the values of each element of the array are as follows:

```julia
out_i = max(input_i, v)

```

where `v` is some arbitrary scalar value. (In this case, zero.)

In Python, this function is called `maximum` (or `fmax`) which is different from `max`. It is part of `numpy`. Example:

```julia
output_array = numpy.fmax(input_array, 0.0)

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [October 3, 2024, 11:19am UTC](https://discourse.julialang.org/t/function-to-obtain-the-maximum-value-of-each-element-of-an-array-with-a-second-argument-of-zero/120852/2 "2024-10-03T11:19:44Z")

</div>

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
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

```
