vstack()是Ruby中的內置方法,它通過將接收器與給定矩陣垂直堆疊而返回一個新矩陣。
它需要一個垂直堆疊的矩陣。
用法: mat1.vstack(mat2)
參數:該函數需要一個要垂直堆疊的矩陣。
返回值:堆疊完成後返回結果矩陣。
例子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]]
相關用法
- Ruby Matrix zero?()用法及代碼示例
- Ruby Matrix lup()用法及代碼示例
- Ruby Matrix inv()用法及代碼示例
- Ruby Matrix I()用法及代碼示例
- Ruby Matrix zero()用法及代碼示例
- Ruby Matrix det()用法及代碼示例
- Ruby Matrix eql?用法及代碼示例
- Ruby Matrix t()用法及代碼示例
- Ruby Matrix row()用法及代碼示例
- Ruby Matrix tr()用法及代碼示例
- Ruby Matrix minor()用法及代碼示例
- Ruby Matrix empty?()用法及代碼示例
- Ruby Matrix lup_decomposition()用法及代碼示例
- Ruby Matrix normal?用法及代碼示例
- Ruby Matrix rank()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Matrix vstack() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。