红宝石 |矩阵 vstack()函数
vstack()是 Ruby 中的一个内置方法,通过将接收器与给定矩阵垂直堆叠,返回一个新矩阵。
它需要一个垂直堆叠的矩阵。
Syntax: mat1.vstack(mat2)
Parameters: The function needs a matrix which is to be stacked vertically.
Return Value: It returns resultant matrix after stacking is done.
示例 1 :
# Ruby program for vstack() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 21], [31, 18]]
mat2 = Matrix[[4, 6], [3, 9]]
# prints the resultant matrix
puts mat1.vstack(mat2)
输出:
Matrix[[1, 21], [31, 18], [4, 6], [3, 9]]
示例 2 :
# Ruby program for vstack() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[3, 5, 9], [10, 19, 123]]
mat2 = Matrix[[12, 12, 13], [19, 18, 89]]
# prints the resultant matrix
puts mat1.vstack(mat2)
输出:
Matrix[[3, 5, 9], [10, 19, 123], [12, 12, 13], [19, 18, 89]]