红宝石 |向量 zero()函数
zero()是 Ruby 中的内置方法,返回大小为 N 且元素等于 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.
示例 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
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
输出:
Vector[0, 0, 0, 0]
示例 2 :
红宝石
#Ruby program for zero method in Vector
#Include matrix
require "matrix"
#Initialize the vector
vec1
= Vector.zero(3)
#prints the new vector
puts vec1
输出:
Vector[0, 0, 0]