map
map(f, c...) -> collection
Transform collection c
by applying f
to each element.
For multiple collection arguments, apply f
elementwise.
julia> map((x) -> x * 2, [1, 2, 3])
3-element Array{Int64,1}:
2
4
6
julia> map(+, [1, 2, 3], [10, 20, 30])
3-element Array{Int64,1}:
11
22
33
Examples
julia> array = Int[1,2,3]
map(x -> x + 1, array)
3-element Array{Int64,1}:
2
3
4
julia> array = Int[1,2,3]
map(x -> x * 2, array)
3-element Array{Int64,1}:
2
4
6
julia> map((x) -> x^3, [1 2 3])
1x3 Array{Int64,2}:
1 8 27
julia> function Foo(x,y)
return 2(x+y)
end
julia> map(Foo, [1 2 3], ones(1, 3))
1x3 Array{Float64,2}:
4.0 6.0 8.0
See Also
append!, delete!, deleteat!, empty!, endof, filter, filter!, gc, get!, getkey, haskey, insert!, isempty, keys, map, map!, merge, merge!, pop!, prepend!, push!, reduce, resize!, shift!, splice!, unshift!, values,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.