在 Julia 中创建从集合到数组的元素副本 – copyto!() 方法
copyto!()
是 julia 中的内置函数,用于将指定集合src中的所有元素复制到数组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.
示例 1:
# 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)
输出:
示例 2:
# 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)
输出: