Ruby 矩阵 eql?函数
eql? 是Ruby中一个内置的方法,它返回一个布尔值。如果两个矩阵都相等,则返回真,否则返回假。
语法 :mat1. eql? (mat2)
参数 :该函数需要两个矩阵mat1和mat2进行比较。
返回值 :如果两个矩阵相等,则返回真,否则返回假。
示例 1 :
# Ruby program for eql? method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 21], [31, 18]]
mat2 = Matrix[[1, 21], [31, 18]]
# Prints if both are equal or not
puts mat1.eql?(mat2)
输出 :
true
例2 :
# Ruby program for eql? method in Matrix
# Include matrix
require "matrix"
# Initializes the matrix
mat1 = Matrix[[1, 21], [31, 18]]
mat2 = Matrix[[1, 16], [31, 28]]
# Prints if both are equal or not
puts mat1.eql?(mat2)
输出 :
false