Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Vector zero() function

  • Last Updated : 19 Jan, 2021

The zero() is an inbuilt method in Ruby returns the vector of size N with elements equals to 0.

Syntax: Vector.zero(N)

Parameters: The function accepts a parameter which represents the size of the array.

Return Value: It returns the vector of size N with elements equals to 0. 
 

Example 1:  



Ruby




#Ruby program for zero method in Vector
 
#Include matrix
require "matrix"
 
#Initialize the vector
    vec1
    = Vector.zero(4)
 
#prints the new vector
          puts vec1

Output

Vector[0, 0, 0, 0]

Example 2

Ruby




#Ruby program for zero method in Vector
 
#Include matrix
require "matrix"
 
#Initialize the vector
    vec1
    = Vector.zero(3)
 
#prints the new vector
          puts vec1

Output

Vector[0, 0, 0]

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :