📜  红宝石 |向量 to_matrix()函数

📅  最后修改于: 2022-05-13 01:54:20.709000             🧑  作者: Mango

红宝石 |向量 to_matrix()函数

to_matrix()是 Ruby 中的一个内置方法,它返回带有向量元素的单列矩阵。

示例 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]]