to_a()是Ruby中的內置方法,它返回一個數組,該數組按行具有矩陣的所有元素。
用法: mat1.to_a()
參數:該函數需要要轉換為數組的矩陣。
返回值:返回一個數組。
例子1:
# Ruby program for to_a() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[3, 12], [2, 8]]
# Prints the to_a matrix
puts mat1.to_a()
輸出:
3 12 2 8
例子2:
# Ruby program for to_a() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 0], [6, 1], [1, 2]]
# converted to array
arr = mat1.to_a()
# Prints the array
puts arr
輸出:
1 0 6 1 1 2
相關用法
- Ruby Matrix det()用法及代碼示例
- Ruby Matrix lup()用法及代碼示例
- Ruby Matrix I()用法及代碼示例
- Ruby Matrix zero()用法及代碼示例
- Ruby Matrix inv()用法及代碼示例
- Ruby Matrix tr()用法及代碼示例
- Ruby Matrix zero?()用法及代碼示例
- Ruby Matrix row()用法及代碼示例
- Ruby Matrix t()用法及代碼示例
- Ruby Matrix eql?用法及代碼示例
- Ruby Matrix trace()用法及代碼示例
- Ruby Matrix row_vectors()用法及代碼示例
- Ruby Matrix row_size()用法及代碼示例
- Ruby Matrix square?()用法及代碼示例
- Ruby Matrix unitary?()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Matrix to_a() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。