红宝石 |矩阵 row_vectors()函数
row_vectors()是 Ruby 中的一个内置方法,它返回代表矩阵中每一行的向量。
Syntax: mat1.row_vectors()
Parameters: The function does not takes any mandatory parameter.
Return Value: It returns vectors representing the rows.
示例 1 :
# Ruby program for row_vectors() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[6, 432], [54, 323]]
# Prints the rows in vectors
puts mat1.row_vectors()
输出:
Vector[6, 432]
Vector[54, 323]
示例 2 :
# Ruby program for row_vectors() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 1, 1],[2, 2, 2],[3, 5, 6]]
# Prints the rows in vectors
puts mat1.row_vectors()
输出:
Vector[1, 1, 1]
Vector[2, 2, 2]
Vector[3, 5, 6]