Array type operators

Index operator

Access array elements by indices or logical values.

See index operator.

[ ]

1d indexing

array1d = [1,2,3]
array1d[1]          // 2

2d Indexing

array2d = [1,2;3,4]
array2d[1,0]        // 3

Colon operator

Create a sequence of float values.

See colon operator.

:

Binary

[1:5]         // [1,2,3,4,5]

Ternary

[1:2:5]       // [1,3,5]

Equality operators

Check float[], bool[] or string[] for equality.

Two arrays are equal if they have equal dimensions and equal elements.

Return type: bool

==

Equality

[1,2]        == [1,2]         // true
["a","b"]    == ["a";"b"]     // false
[true,false] == [true,true]   // false

!=

Inequality

[1,2]        != [1;2]         // true
["a","b"]    != ["a";"b"]     // true
[true,true]  != [true,true]   // false

Relational operators

Compare float[] or string[].

Two arrays are element-wise compared, row by row. If an element is less, the respective array is less. If the first rows are equal, the array with less columns is less. Otherwise the array with less rows is less.

Return type: bool

<

Less

[1,2]        <  [1,3]         // true
["a","b"]    <  ["a";"b"]     // false

<=

Less or equal

[1,2]        <= [1,2]         // true
["a";"b"]    <= ["a"]         // false

>

Greater

[1,3]        >  [1,2]         // true
["a";"b"]    >  ["a"]         // true

>=

Greater or equal

[1,2,3]      >= [1,2]         // true
["a";"b"]    >= ["a";"b"]     // true

String concatenation operators

Concatenate string with string[], float[] or bool[].

Return type: string

+

String-string[] concatenation

a = "array: " + ["element"]
a = ["element"] + " is an array"

String-float[] concatenation

a = "array:\n" + [1,2;3,4]
a = [1,2;3,4] + "\nis an array"

String-boolean[] concatenation

a = "array: " + [true,true]
a = [true,true] + " is an array"

Element-wise array operators

Element-wise operators have a preceding dot. They perform the operator on each element and return the results in an array with the same dimensions as the input array(s). The dimensions of two arrays must be equal.

Element-wise: Logical operators

Element-wise logical operations on bool[].

Return type: bool[]

.!

Negation

.![true,false]                     // [false,true]

.||

Logical Or

[true,false]  .|| true             // [true,true]
false         .|| [false;true]     // [false;true]
[false,true]  .|| [false,false]    // [false,true]

.&&

Logical And

[false;true]  .&& true             // [false;true]
false         .&& [true;true;true] // [false;false;false]
[true,false]  .&& [false,true]     // [false,false]

Element-wise: Arithmetic operators

Element-wise arithmetic operations on float[].

Return type: float[]

.+

Plus

[1,2]         .+  1                // [2,3]
1             .+  [1;2]            // [2;3]
[1,2]         .+  [2,1]            // [3,3]

Unary plus

.+[1,2]                            // [1,2]

.-

Minus

[1,2;3,4]     .-  1                // [0,1;2,3]
3             .-  [1,2]            // [2,1]
[3;2]         .-  [2;1]            // [1;1]

Unary minus

.-[1;2]                            // [-1;-2]

.*

Multiplication

[4,2]         .*  2.5              // [10,5]
-4            .*  [0.25;-0.75;-1]  // [-1;3;4]
[1,2;3,4]     .*  [4,3;2,1]        // [4,6;6,4]

./

Division

 [4;3]         ./  2                // [2;1.5]
12            ./  [2,3,4]          // [6,4,3]
[1.6,3.8]     ./  [0.8,1.9]        // [2,2]

.%

Modulus (remainder)

[8;-5;0]      .%  3                // [2;-2;0]
7             .%  [2.7,-3]         // [1.6,1]
[-5,3.8]      .%  [-3,0.7]         // [-2,0.3]

Element-wise: Equality operators

Element-wise check float[], bool[] or string[] for equality.

Return type: bool[]

.==

Equality

1             .== [1,2]            // [true,false]
["a","b"]     .== "b"              // [false,true]
[true;false]  .== [true;false]     // [true;true]

.!=

Inequality

[1,1;2,2]     .!= [1,2;1,2]        // [false,true;true,false]
["a"]         .!= "a"              // [false]
false         .!= [true]           // [true]

Element-wise: Relational operators

Element-wise compare float[] or string[].

Return type: bool[]

.<

Less

1             .<  [1,2]            // [false,true]
["a","b"]     .<  "b"              // [true,false]
[1,2;2,1]     .<  [2,1;1,2]        // [true,false;false,true]

.<=

Less or equal

1             .<= [1,2]            // [true,true]
["a";"b";"c"] .<= "b"              // [true;true;false]
["a","b"]     .<= ["b","a"]        // [true,false]

.>

Greater

[1,2;3,4]     .>  [1,1;3,3]        // [false,true;false,true]
"a"           .>  ["a";"a"]        // [false;false]
["a";"b"]     .>  "a"              // [false;true]

.>=

Greater or equal

[1;2;3]       .>= [2;2;2]          // [false;true;true]
2             .>= [1,2,3]          // [true,true,false]
["a"]         .>= "a"              // [true]

Element-wise: String concatenation operators

Element-wise concatenate string, string[] with string[], float[], bool[] or string[] with string, float, bool.

Return type: string[]

.+

String-string concatenation

["a","b"]     .+  "c"              // ["ac","bc"]
"a"           .+  ["b";"c"]        // ["ab";"ac"]
["a","b"]     .+  ["c","d"]        // ["ac","bd"]

String-float concatenation

["a","b"]     .+  1                // ["a1","b1"]
"a"           .+  [1,2;3,4]        // ["a1","a2";"a3","a4"]
[1;2]         .+  ["a";"b"]        // ["1a";"2b"]

String-boolean concatenation

[true;false]  .+  "a"              // ["truea";"falsea"]
"a"           .+  [true]           // ["atrue"]
["a";"b"]     .+  [false;true]     // ["afalse";"btrue"]

Related