Open In App

Ruby | Matrix zero() function

Improve
Improve
Like Article
Like
Save
Share
Report

The zero() is an inbuilt method in Ruby returns an N x M zero matrix where each element is zero.

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.

Example 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


Output:

Matrix[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]

Example 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


Output:

Matrix[[0, 0], [0, 0]]

Last Updated : 07 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads