empty?()是Ruby中的內置方法,返回布爾值。如果矩陣為空,則返回true,否則返回false。
用法:mat1.empty?()
參數:該函數不接受任何參數。
返回值:它返回一個布爾值。
例子1:
# Ruby program for empty() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 21], [31, 18]]
# prints if empty or not
puts mat1.empty?()
輸出:
false
例子2:
# Ruby program for empty() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[]
# prints if empty or not
puts mat1.empty?()
輸出:
true
相關用法
- Ruby Set empty?()用法及代碼示例
- Ruby Symbol empty?用法及代碼示例
- Ruby StringScanner empty?用法及代碼示例
- Ruby SizedQueue empty?用法及代碼示例
- Ruby Queue empty?用法及代碼示例
- Ruby Hash empty?用法及代碼示例
- Ruby Matrix zero()用法及代碼示例
- Ruby Matrix det()用法及代碼示例
- Ruby Matrix eql?用法及代碼示例
- Ruby Matrix t()用法及代碼示例
- Ruby Matrix lup()用法及代碼示例
- Ruby Matrix tr()用法及代碼示例
- Ruby Matrix zero?()用法及代碼示例
- Ruby Matrix inv()用法及代碼示例
- Ruby Matrix I()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Matrix empty?() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。