Ruby | Matrix zero() function
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:
require "matrix"
mat1 = Matrix.zero( 4 , 3 )
puts mat1
|
Output:
Matrix[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
Example 2:
require "matrix"
mat1 = Matrix.zero( 2 , 2 )
puts mat1
|
Output:
Matrix[[0, 0], [0, 0]]
Last Updated :
07 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...