Creating a copy of elements from a collection to an array in Julia – copyto!() Method
The copyto!()
is an inbuilt function in julia which is used to copy all elements from the specified collection src to array dest.
Syntax:
copyto!(dest::AbstractArray, src)
Parameters:
- dest::AbstractArray: Specified destination array.
- src: Specified source collection.
Returns: It returns the copied elements from the specified collection src to array dest.
Example 1:
a = [ 1 , 2 , 3 , 4 , 5 ];
b = zeros( 8 );
copyto !(b, a);
println(b)
|
Output:
Example 2:
a = [ 1. , 2. , 3. , 4. , 5. ];
b = ones( 8 );
copyto !(b, a);
println(b)
|
Output:
Last Updated :
01 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...