square?()是Ruby中的內置方法,返回布爾值。如果是方矩陣,則返回true;否則返回false。
用法:mat1.square?()
參數:該函數需要檢查矩陣是否為正方形矩陣。
返回值:如果是方矩陣,則返回true,否則返回false。
例子1:
# Ruby program for square?() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[3, 12], [2, 8]]
# Prints if square? or not
puts mat1.square?()
輸出:
true
例子2:
# Ruby program for square?() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 0], [0, 1], [1, 2]]
# Prints if square? or not
puts mat1.square?()
輸出:
false
相關用法
- Ruby Matrix tr()用法及代碼示例
- Ruby Matrix eql?用法及代碼示例
- Ruby Matrix row()用法及代碼示例
- Ruby Matrix zero?()用法及代碼示例
- Ruby Matrix t()用法及代碼示例
- Ruby Matrix inv()用法及代碼示例
- Ruby Matrix zero()用法及代碼示例
- Ruby Matrix det()用法及代碼示例
- Ruby Matrix I()用法及代碼示例
- Ruby Matrix lup()用法及代碼示例
- Ruby Matrix permutation?用法及代碼示例
- Ruby Matrix orthogonal?用法及代碼示例
- Ruby Matrix lower_triangular?用法及代碼示例
- Ruby Matrix normal?用法及代碼示例
- Ruby Matrix minor()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Matrix square?() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。