Open In App

Set elements at a given index of array in Julia – setindex!() Method

Improve
Improve
Like Article
Like
Save
Share
Report

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: 
 

 


Last Updated : 24 Feb, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads