halcon中编程运算符_R编程中的运算符

halcon中编程运算符

Operators in a programming language are certain tokens or symbols that perform specific operations on the arguments supplied. The arguments are known as operands. These operations are usually arithmetic or logical in nature. R supports various operators across different categories.

编程语言中的运算符是对提供的参数执行特定操作的某些标记或符号。 这些参数称为操作数 。 这些操作通常本质上是算术或逻辑的。 R支持不同类别的各种运算符。

R操作员分类 (R Operators Classification)

We can classify R operators into the following categories.

我们可以将R运算符分为以下几类。

  1. Arithmetic

    算术
  2. Relational

    关系型
  3. Logical

    逻辑上
  4. Assignment

    分配
  5. Special operators

    特殊运营商

1. R中的算术运算符 (1. Arithmetic Operators in R)

These are the operators that perform basic arithmetic operations like addition, subtraction, multiplication, and division. In addition, there are also operators for modulus and exponentiation.

这些是执行基本算术运算(如加法,减法,乘法和除法)的运算符。 此外,还有模和幂运算符。

These operators work on both single variables and vectors. The use of these operators is straightforward.

这些运算符可用于单个变量和向量。 这些运算符的使用很简单。

The following code snippet will help you gain an understanding of these operators.

以下代码段将帮助您了解这些运算符。


#Mathemetical operations in single numeric values.
> a=2
> b=4
#Addition -- Operator +
> a+b
[1] 6
#Subtraction -- Operator -
> b-a
[1] 2
#Multiplication -- Operator *
> a*b
[1] 8
#Division -- Operator /
> b/a
[1] 2

Similarly, we also have operators for exponentiation ^ and modulo %%. These are illustrated below. The modulo operator gives the remainder of a division operation.

同样,我们也有求幂^和取模%%运算符。 这些说明如下。 模运算符给出除法运算的余数。


#Modulo Operator - %%
> x=10
> y=4
> z=x%%y
> z
[1] 2
#Exponentiation Operator - ^
> w=x^y
> w
[1] 10000

These operators also work on a vector level. Addition, subtraction and other operations work on an element by element level. This is illustrated in the code below.

这些运算符还在矢量级别上工作。 加,减和其他运算在一个元素级别上进行。 下面的代码对此进行了说明。


#Define 2 vectors
> vec1=c(2,3,5,1,4)
> vec2=c(3,4,5,1,7)
#Addition to two vectors
> vec1+vec2
[1]  5  7 10  2 11
#Subtraction of two vectors
> vec1-vec2
[1] -1 -1  0  0 -3
#Multiplication of two vectors
> vec1*vec2
[1]  6 12 25  1 28
#Division of two vectors
> vec1/vec2
[1] 0.6666667 0.7500000 1.0000000 1.0000000 0.5714286
#Exponentiation of a vector using integer
> vec1^2
[1]  4  9 25  1 16
#Element-wise exponentiation
> vec1^vec2
[1]     8    81  3125     1 16384

2. R中的关系运算符 (2. Relational Operators in R)

These are used to compare two numbers or two vectors. The main relational operators are greater than (>) , less than (<) and equal to (==).

这些用于比较两个数字或两个向量。 主要的关系运算符大于> ), 小于< )且等于== )。

There are other compound operators greater than or equal to (>=) and less than or equal to(<=). The output of these operators is a Boolean value, TRUE or FALSE. These are illustrated in the given code snippet.

还有其他大于或等于>= )且小于或等于<= )的复合运算符。 这些运算符的输出是布尔值TRUE或FALSE。 这些在给定的代码片段中进行了说明。

When applied to vectors, these operators perform an element-wise comparison and give a vector of corresponding Boolean values as a result.

当将这些运算符应用于向量时,它们将执行逐元素比较,并给出相应布尔值的向量作为结果。


> x
[1] 10
> y
[1] 4
> z
[1] 2
> w
[1] 10000
> x < w
[1] TRUE
> y > z
[1] TRUE
> x == w
[1] FALSE
> x <= x
[1] TRUE
> y >= z
[1] TRUE
> vec1

3. R逻辑运算符 (3. R Logical Operators)

These take Boolean values as operands and give Boolean value as output. These are AND (&), OR (|) and NOT (!). These can be used as follows:

这些将布尔值作为操作数,并将布尔值作为输出。 它们是AND( & ),OR( | )和NOT( ! )。 这些可以如下使用:


#Logical AND - Gives TRUE only if both the holding conditions are TRUE.
> 2<4&4>1
[1] TRUE
> 8>8&9>8
[1] FALSE

#Logical OR - Gives TRUE if any of the holding condtions are TRUE.
> (1.3-3.14<0)|(3==0)
[1] TRUE

#Logical NOT - Simply negates the value from FALSE to TRUE or TRUE to FALSE.
> !(30>2)
[1] FALSE

Similar to the logical operators above, we also have element-wise logical operators – AND (&&) and OR (||). These are used upon vectors and give results corresponding to only the first elements of two vectors. This can be shown in the following code.

与上面的逻辑运算符类似,我们还有按元素的逻辑运算符– AND(&&)和OR(||)。 这些用于矢量,并给出仅与两个矢量的第一个元素相对应的结果。 可以在下面的代码中显示。


> vec1
[1] 2 3 5 1 4
> vec3
[1] 1 0 0 0 0

> vec1&vec3
[1]  TRUE FALSE FALSE FALSE FALSE
> vec1&&vec3
[1] TRUE

> vec1|vec3
[1] TRUE TRUE TRUE TRUE TRUE
> vec1||vec3
[1] TRUE
> !vec1
[1] FALSE FALSE FALSE FALSE FALSE

4. R赋值运算符 (4. R Assignment Operators)

The assignment operators are used to assign values to a variable. There are three assignment operators in R, left assignment (<-), right assignment (->) and equal to (=). These have been discussed in detail in the variables tutorial here.

赋值运算符用于将值赋给变量。 R中有三个赋值运算符,左赋值( <- ),右赋值( - >)等于( = )。 这些已在此处的变量教程中进行了详细讨论。

5. R中的特殊运算符 (5. Special Operators in R)

R has some operators defined for special purposes. Some of these are:

R有一些为特殊目的定义的运算符。 其中一些是:

  • Sequence Generator – Specified by a colon symbol (:)
    • Used to define a sequence range.
    • 2:10 – means a sequence from 2 to 10.

    序列发生器 –用冒号(:)指定
    • 用于定义序列范围。
    • 2:10 –表示从2到10的顺序。
  • List Indexing Operator – Specified by a dollar sign $.
    • Facilitates extracting an element of a list by its name.

    列表索引运算符 –由美元符号$指定。
    • 便于按列表名称提取列表的元素。
  • Model Formula Operator – Specified by a tilde sign ~
    • Used to define a re-usable formula along with its dependent variables.

    模型公式运算符 -由波浪号指定〜
    • 用于定义可重用公式及其因变量。

We will delve deeper into the list indexing and model formula operators in our further advanced tutorials. The sequence generator works as follows.

我们将在进一步的高级教程中深入研究列表索引和模型公式运算符。 序列发生器的工作原理如下。


> seq2 <- 2:10
> seq2
[1]  2  3  4  5  6  7  8  9 10

翻译自: https://www.journaldev.com/35056/operators-in-r-programming

halcon中编程运算符

你可能感兴趣的:(python,java,机器学习,算法,大数据)