# Is there a way to do elementwise function argument?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-do-elementwise-function-argument/50178
**Category:** General Usage
**Created:** [November 15, 2020, 9:40am UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-elementwise-function-argument/50178 "2020-11-15T09:40:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![minetest2048](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/minetest2048/32/45961_2.png) [@minetest2048](https://discourse.julialang.org/u/minetest2048)
#### Post date: [November 15, 2020, 9:40am UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-elementwise-function-argument/50178/1 "2020-11-15T09:40:00Z")

</div>

For example I have a array [4,5,6,7] and I want to clamp the first element to 1, second element to 2, third element to 3 and fourth element to 4. Can I do something like `clamp.([4,5,6,7],[0,0,0,0],[1,2,3,4])` and somehow Julia interprets it as `[clamp(4,0,1),clamp(5,0,2),clamp(6,0,4),clamp(7,0,4)]`?

---

<div class="post-metadata">

### Author: ![minetest2048](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/minetest2048/32/45961_2.png) [@minetest2048](https://discourse.julialang.org/u/minetest2048)
#### Post date: [November 15, 2020, 9:51am UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-elementwise-function-argument/50178/2 "2020-11-15T09:51:12Z")

</div>

Actually `clamp.([4,5,6,7],[0,0,0,0],[1,2,3,4])` is the right syntax for that

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 15, 2020, 2:04pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-elementwise-function-argument/50178/3 "2020-11-15T14:04:56Z")

</div>

You can also do `clamp.([4,5,6,7],0,[1,2,3,4])` to take advantage of the lower bounds all being 0.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [November 15, 2020, 3:11pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-elementwise-function-argument/50178/4 "2020-11-15T15:11:57Z")

</div>

Or even

```julia
clamp.([4,5,6,7], 0, 1:4)

```

---

<div class="post-metadata">

### Author: ![minetest2048](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/minetest2048/32/45961_2.png) [@minetest2048](https://discourse.julialang.org/u/minetest2048)
#### Post date: [November 15, 2020, 10:58pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-elementwise-function-argument/50178/5 "2020-11-15T22:58:53Z")

</div>

I thought the dot operator only works for 1 array inputs and the others are scalars, something like `sin.([1,2,3,4])`. Is there a tutorial/documentation on what the dot operator can or cannot do?

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [November 15, 2020, 11:46pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-elementwise-function-argument/50178/6 "2020-11-15T23:46:24Z")

</div>

It’s actually in several places in the manual, here’s a [start](https://docs.julialang.org/en/v1/manual/functions/#man-vectorized). The dot (not really an operator on its own) is syntactic sugar for broadcasting.
