当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Scala Vector -用法及代码示例


-是一个内置方法红 gems 返回两个向量的减法

用法: vec1 - vec2
参数: The function does not accepts any parameter.
Return Value: It returns the subtraction two vectors.

示例 1:

CPP


#Ruby program for - method in Vector
#Include matrix
require "matrix"
#Initialize the vectors
    vec1
    = Vector[1, 2] vec2 = Vector[1, 4]
#prints the new vector
                          puts vec1
                          - vec2

输出:

Vector[0, -2]

示例 2:

CPP


#Ruby program for - method in Vector
#Include matrix
require "matrix"
#Initialize the vectors
    vec1
    = [ 1, 4, 5 ] vec2 = [ 1, 4, 7 ]
#prints the new vector
                         puts vec1
                         - vec2

输出:

Vector[0, 0, -2]

相关用法


注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 Ruby | Vector – method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。