Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Matrix zero() function

  • Last Updated : 07 Jan, 2020

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]]
My Personal Notes arrow_drop_up
Recommended Articles
Page :