The []() is an inbuilt method in Ruby returns the element at the i-th row and the j-th column.
Syntax: mat1[i, j]
Parameters: The function needs the row number i and column number j whose position element is to be returned.
Return Value: It returns the element at the position mat[i][j].
Example 1:
require "matrix"
mat1 = Matrix[[ 1 , 21 ], [ 31 , 18 ]]
puts mat1[ 1 , 1 ]
|
Output:
18
Example 2:
require "matrix"
mat1 = Matrix[[ 89 , 12 , 12 ], [ 8 , 5 , 23 ], [ 1 , 2 , 9 ]]
puts mat1[ 2 , 2 ]
|
Output:
9
Last Updated :
07 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...