红宝石 |矩阵 == 方法
==是 Ruby 中的一个内置方法,它返回一个布尔值。如果两个矩阵相等,则返回 true,否则返回 false。
Syntax: mat1 == mat2
Parameters: The function need two matrix mat1 and mat2 which are to be compared.
Return Value: It returns true if both the matrix are equal or else it returns false.
示例 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