📜  红宝石 |向量 zero()函数

📅  最后修改于: 2022-05-13 01:55:30.220000             🧑  作者: Mango

红宝石 |向量 zero()函数

zero()是 Ruby 中的内置方法,返回大小为 N 且元素等于 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]