📜  在 Julia 中的给定数组索引处设置元素 – setindex!() 方法

📅  最后修改于: 2022-05-13 01:55:48.137000             🧑  作者: Mango

在 Julia 中的给定数组索引处设置元素 – setindex!() 方法

setindex!()是 julia 中的一个内置函数,用于将给定数组X中的值存储在由 inds 指定的 A 的某个子集中。

句法:

setindex!(A, X, inds...)

参数:

  • A:指定函数。
  • X:指定数组。
  • inds:指定索引。

返回:它不返回任何值。示例 1:

Python
# Julia program to illustrate
# the use of Array setindex!() method
 
# This function store values from an array
# X within some subset of A as
# specified by inds.
A = zeros(2, 2);
setindex !(A, [5, 10], [1, 2]);
A[[3, 4]] = [15, 20];
println(A)


Python
# Julia program to illustrate
# the use of Array setindex!() method
 
# This function store values from an array
# X within some subset of A as
# specified by inds.
A = ones(2, 2);
setindex !(A, [2, 4], [1, 2]);
A[[3, 4]] = [6, 8];
println(A)


输出:

示例 2:

Python

# Julia program to illustrate
# the use of Array setindex!() method
 
# This function store values from an array
# X within some subset of A as
# specified by inds.
A = ones(2, 2);
setindex !(A, [2, 4], [1, 2]);
A[[3, 4]] = [6, 8];
println(A)

输出: