Ruby | Vector zero() function
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]
Contact Us