红宝石 |矩阵平方?()函数
square?()是 Ruby 中的一个内置方法,它返回一个布尔值。如果是方阵则返回真,否则返回假。
Syntax: mat1.square?()
Parameters: The function needs the matrix to be checked for square matrix or not.
Return Value: It returns true if it is a square matrix, else it returns 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