Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use `map` with fixed input?

Tags:

mapping

julia

Suppose I do f(x,y) = 2x + ythen 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] ?

like image 610
RangerBob Avatar asked Aug 09 '16 14:08

RangerBob


2 Answers

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
like image 142
Chris Rackauckas Avatar answered Oct 16 '22 13:10

Chris Rackauckas


You can use map(x->f(x,1), [2,4,6]) to accomplish this.

like image 45
Jeff Bezanson Avatar answered Oct 16 '22 12:10

Jeff Bezanson