红宝石 |向量元素()函数
elements()是 Ruby 中的一个内置方法,返回使用数组创建的向量
Syntax: Vector.elements(array)
Parameters: The function accepts a parameter array
Return Value: It returns the vector which is created using the array.
示例 1 :
#Ruby program for elements() method in Vector
#Include matrix
require "matrix"
#Initialize the array
arr
= [ 1, 2, 3 ]
#Initialize the vector
vec1
= Vector.elements(arr)
#prints the new vector
puts vec1
输出:
Vector[1, 2, 3]
示例 2 :
#Ruby program for elements() method in Vector
#Include matrix
require "matrix"
#Initialize the vector
vec1
= Vector.elements([ 1, 2, 3 ])
#prints the new vector
puts vec1
输出:
Vector[1, 2, 3]