红宝石 |向量 to_matrix()函数
to_matrix()是 Ruby 中的一个内置方法,它返回带有向量元素的单列矩阵。
Syntax: vec1.to_matrix()
Parameters: The function accepts no parameter
Return Value: It returns the matrix of single column with elements of vector
示例 1 :
# Ruby program for to_matrix() method in Vector
# Include matrix
require "matrix"
# Initialize the vector
vec1 = Vector[1, 2, 3]
# Prints the matrix with single column
puts vec1.to_matrix()
输出:
Matrix[[1], [2], [3]]
示例 2 :
# Ruby program for to_matrix() method in Vector
# Include matrix
require "matrix"
# Initialize the vector
vec1 = Vector[1, 1]
# Prints the matrix with single column
puts vec1.to_matrix()
输出:
Matrix[[1], [1]]