Related Articles

Related Articles

Set elements at a given index of array in Julia – setindex!() Method
  • Last Updated : 01 Apr, 2020

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :