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