Suppose I do f(x,y) = 2x + y
then map(f, [2,4,6],[1,1,1])
I will get:
3-element Array{Int64,1}:
5
9
13
If I do map(f, [2,4,6],1)
, i.e., I want to suppose that the second input is always the same,
I will get:
1-element Array{Any,1}:
5
So this does not work. Is there a way to do this without coding a Vector [1,1,1]
?
Broadcast "acts like" it changes the arrays to be a size which works, and maps:
broadcast(f, [2,4,6],1)
outputs:
Int64[3]
5
9
13
You can use map(x->f(x,1), [2,4,6])
to accomplish this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With