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