Skip to content
Related Articles

Related Articles

Improve Article
Set elements at a given index of array in Julia – setindex!() Method
  • Last Updated : 24 Feb, 2021

The setindex!() is an inbuilt function in julia which is used to store values from the given array X within some subset of A as specified by inds.
 

Syntax: 

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

Parameters: 

  • A: Specified function.
  • X: Specified array.
  • inds: Specified index.

Returns: It does not return any values. 
 
Example 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)

Output: 
 

Example 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)

Output: 
 

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :