红宝石 |矩阵 zero()函数
zero()是 Ruby 中的一个内置方法,它返回一个 N x M 零矩阵,其中每个元素都为零。
Syntax: mat1.zero(N, M)
Parameters: The function accepts two mandatory parameters N and M which is the size of the matrix.
Return Value: It returns the zero matrix of size N x M.
示例 1 :
# Ruby program for zero() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
# using zero method
mat1 = Matrix.zero(4 , 3)
# Print the matrix
puts mat1
输出:
Matrix[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
示例 2 :
# Ruby program for zero() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
# using zero method
mat1 = Matrix.zero(2, 2)
# Print the matrix
puts mat1
输出:
Matrix[[0, 0], [0, 0]]