Ruby Vector to_matrix()函数
to_matrix() 是Ruby中的一个内置方法,用于返回带有向量元素的单列矩阵。
语法 :vec1.to_matrix()
参数 :该函数不接受任何参数
返回值 : 返回单列矩阵与矢量元素的关系。
例子 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]]