map!(f,collection)

..  map!(function, collection)

In-place version of :func:`map`.

Examples

julia> foo = [1   2   3];
julia> map!((x) -> x^3, foo);
julia> foo
1x3 Array{Int64,2}:
 1      8       27

Passing destination as a param

julia> function F(x,y)
                x^2+y^2
            end
julia> bar = Array(Int64,1,3);
julia> map!(F,   bar,    [3    6   12],   [4   8   5])
1x3 Array{Int64,2}:
 25    100     169
julia> A = [1, 2, 3, 4];
julia> B = similar(A);
julia> map!(x -> x^2, B, A)
4-element Array{Int64,1}:
  1
  4
  9
 16

In this example, the map! function applies the provided function x -> x^2 element-wise to the collection A, and stores the result in the preallocated array B, which is created using the similar function to match the size and element type of A. The resulting array B contains the squared values of the elements in A.

Note that destination (in this case, B) must be at least as large as the first collection (A) to store the mapped values.

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.

*Required Field
Details

Checking you are not a robot: