當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。