Ruby | Matrix to_a() function
The to_a() is an inbuilt method in Ruby returns an array which has all the elements of the matrix row-wise.
Syntax: mat1.to_a()
Parameters: The function needs the matrix which is to be converted to an array.
Return Value: It returns an array.
Example 1:
require "matrix"
mat1 = Matrix[[ 3 , 12 ], [ 2 , 8 ]]
puts mat1.to_a()
|
Output:
3
12
2
8
Example 2:
require "matrix"
mat1 = Matrix[[ 1 , 0 ], [ 6 , 1 ], [ 1 , 2 ]]
arr = mat1.to_a()
puts arr
|
Output:
1
0
6
1
1
2
Last Updated :
07 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...