红宝石 |矩阵 to_matrix()函数
to_matrix()是 Ruby 中的一个内置方法,它返回一个只有自身的矩阵。
Syntax: mat1.to_matrix()
Parameters: The function needs the matrix which is to be returned.
Return Value: It returns an matrix, or self.
示例 1 :
# Ruby program for to_matrix() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[3, 12], [2, 8]]
# Prints the to_matrix matrix
puts mat1.to_matrix()
输出:
Matrix[[3, 12], [2, 8]]
示例 2 :
# Ruby program for to_matrix() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 0], [6, 1], [1, 2]]
# Prints the to_matrix matrix
puts mat1.to_matrix()
输出:
Matrix[[1, 0], [6, 1], [1, 2]]