Related Articles

Related Articles

Creating a copy of elements from a collection to an array in Julia – copyto!() Method
  • Last Updated : 01 Apr, 2020

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate 
# the use of copyto !() method
   
# Getting copied elements from the 
# specified collection src to array dest
a = [1, 2, 3, 4, 5];
b = zeros(8);
copyto !(b, a);
println(b)

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate 
# the use of copyto !() method
   
# Getting copied elements from the 
# specified collection src to array dest
a = [1., 2., 3., 4., 5.];
b = ones(8);
copyto !(b, a);
println(b)

chevron_right


Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :