Comparison of programming languages (array)
{{Short description|List of programming language comparisons}}
{{one source|date=June 2013}}
{{ProgLangCompare}}
This comparison of programming languages (array) compares the features of array data structures or matrix processing for various computer programming languages.
Syntax
= Array dimensions =
The following list contains syntax examples of how to determine the dimensions (index of the first element, the last element or the size in elements).
Some languages index from zero. Some index from one. Some carry no such restriction, or even allow indexing by any enumerated type, not only integers.
class="wikitable sortable" | ||
scope="col" | Languages
! scope="col" | Size ! scope="col" | First ! scope="col" | Last | ||
---|---|---|
Ada
| {{Mono|name | {{Mono|name | {{Mono|name |
ALGOL 68
| {{Mono|UPB name - LWB name+1}} | {{Mono|LWB name}} {{Mono|2 LWB name}} etc. | {{Mono|UPB name}} {{Mono|2 UPB name}} |
APL
| {{Mono|⍴ name | {{Mono|⎕IO}} | {{Mono|(⍴ name)-~⎕IO (⍴ name)[index]-~⎕IO}} |
AWK
| {{Mono|length}} | {{Mono|1}} | {{Mono|asorti}} |
C#, Visual Basic (.NET), Windows PowerShell, F#
| {{Mono|name.Length}} | {{Mono|name.GetLowerBound(dimension)}} | {{Mono|name.GetUpperBound(dimension)}} |
CFML
| {{Mono|arrayLen(name)}} | {{Mono|1}} | {{Mono|name.len()}} |
Ch
| {{Mono|max(shape(name))}} | {{Mono|0}} | {{Mono|max(shape(name))-1}} |
Common Lisp
| {{Mono|(length name)}} | {{Mono|0}} | {{Mono|(1- (length name))}} |
D
| {{Mono|name.length}} | {{Mono|0}} | {{Mono|name.length-1}} {{Mono|$-1}} |
Fortran
| {{Mono|size(name)}} | {{Mono|lbound(name)}} | {{Mono|ubound(name)}} |
Go
| {{Mono|len(name)}} | {{Mono|0}} | {{Mono|len(name) - 1}} |
Haskell
| {{Mono|rangeSize (bounds name)}} | {{Mono|fst (bounds name)}} | {{Mono|snd (bounds name)}} |
ISLISP
| {{Mono|(length name)}} | {{Mono|0}} | {{Mono|(1- (length name))}} |
Icon
| {{Mono|*name}} | {{Mono|1}} | {{Mono|*name}} |
Cobra, D, Haxe, Java, JavaScript, Scala
| {{Mono|name.length}} | {{Mono|0}} | {{Mono|name.length - 1}} |
J
| {{Mono|#name}} | {{Mono|0}} | {{Mono|<:@#name}} |
JavaScript (ES2022)
| {{Mono|name.length}} | {{Mono|0}} {{Mono|name.at(0) {{Cite web|url=https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.at|title=ECMAScript® 2025 Language Specification}} }} | {{Mono|name.length - 1}} {{Mono|name.at(-1)}} |
Julia
| {{Mono|length(name) | {{Mono|begin first.(axes(name))}} | {{Mono|end last.(axes(name))}} |
Lingo
| {{Mono|count(name)}} | {{Mono|1}} | {{Mono|getLast(name)}} |
LiveCode
| {{Mono|length(name)}} | {{Mono|1}} {{Mono|first}} | {{Mono |
1}} {{Mono|last}} | ||
Lua
| {{Mono|#name}} | {{Mono|1 by convention; any integer{{Cite web|url=https://www.lua.org/pil/11.1.html|title=Programming in Lua : 11.1}}}} | {{Mono|#name}} |
Mathematica
| {{Mono|Length[name]}} | {{Mono|1}} {{Mono|First[name]}} | {{Mono |
1}} {{Mono|Last[name]}} | ||
MATLAB, GNU Octave
| {{Mono|length(name)}} | {{Mono|1}} | {{Mono|end}} |
:
| Nim | {{Mono|name.len}} | {{Mono|name.low}}{{Cite web|url=https://nim-lang.org/docs/tut1.html#advanced-types-arrays|title=Nim Tutorial (Part I)}} | {{Mono|name.high}} |
Oberon
| {{Mono|LEN(name)}} | {{Mono|0}} | {{Mono|LEN(name) - 1}} |
Object Pascal
| {{Mono|Length(name)}} | {{Mono|0}} {{Mono|low(name)}} | {{Mono|Length(name)-1}} {{Mono|high(name)}} |
Objective-C (NSArray * only)
| {{Mono|[name count]}} | {{Mono|0}} | {{Mono|[name count] - 1}} |
OCaml
| {{Mono|Array.length name}} | {{Mono|0}} | {{Mono|Array.length name - 1}} |
Perl
| {{Mono|scalar(@name)}} | {{Mono|$[}} | {{Mono|$#name}} |
PHP
| {{Mono|count(name)}} | {{Mono|0}} | {{Mono|count(name) - 1}} |
PL/I
| {{Mono|dim(name[,dim])}} | {{Mono|lbound(name[,dim])}} | {{Mono|hbound(name[,dim])}} |
Python
| {{Mono|len(name)}} | {{Mono|0}} | {{Mono |
1}} {{Mono|len(name) - 1}} | ||
R
| {{Mono|length(name)}} | {{Mono|1}} | {{Mono|length(name)}} |
Raku
| @{{Mono|name.elems}} | {{Mono|0}} | {{Mono|@name.end}} |
Red
| {{Mono|length? name}} | {{Mono|name/1}} {{Mono|first name}} | {{Mono|last name}} |
Ruby
| {{Mono|name.size}} | {{Mono|0}} {{Mono|name.first}} | {{Mono |
1}} {{Mono|name.size - 1}} {{Mono|name.last}} | ||
Rust
| {{Mono|name.len()}} | {{Mono|0}} | {{Mono|name.len() - 1}} |
S-Lang
| {{Mono|length(name)}} | {{Mono|0}} | {{Mono |
1}} {{Mono|length(name)-1}} | ||
Scheme
| {{Mono|(vector-length vector)}} | {{Mono|0}} | {{Mono|(- (vector-length vector) 1)}} |
Smalltalk
| {{Mono|name size}} | {{Mono|1}} {{Mono|name first}} | {{Mono|name size}} {{Mono|name last}} |
Swift
| {{Mono|name.count}} | {{Mono|0}} | {{Mono|name.count - 1}} | ||
Unicon
| {{Mono|*name}} | {{Mono|1}} | {{Mono|*name}} |
Visual Basic
| {{Mono|UBound(name)-LBound(name)+1}} | {{Mono|LBound(name)}} | {{Mono|UBound(name)}} |
Wolfram Language
| {{Mono|Length[name]}} | {{Mono|1}} {{Mono|First[name]}} | {{Mono |
1}} {{Mono|Last[name]}} | ||
Xojo
| {{Mono|UBound(name)}} | {{Mono|0}} | {{Mono|UBound(name)}} |
XPath/XQuery
| {{Mono|count($name)}} | {{Mono|1}} | {{Mono|count($name)}} {{Mono|last()}} {{Mono|array:size(name)}} |
= Indexing =
The following list contains syntax examples of how to access a single element of an array.
class="wikitable" |
scope="col" | Format
! scope="col" | Languages |
---|
{{nowrap|{{Mono|name[index]}} or {{mono|name[index1, index2]}} etc.}}
| ALGOL 58, ALGOL 60, ALGOL 68, AWK, Julia, Modula, Pascal, Object Pascal, C#, S-Lang Icon, Unicon |
{{Mono|name[index]}} or {{mono|name[index1; index2]}} etc. or {{mono|index⌷name}} or {{mono|index1 index2⌷name}} etc. | APL |
{{Mono|name[index]}}
| ActionScript, C, CFML, Ch, Cobra, C++, D, Go, Haxe, Java, JavaScript, Lingo, Lua, Nim, Objective-C ( |
{{Mono|$name[index]}} |
{{Mono|@name[index]}}
| Raku |
{{Mono|name(index)}} or {{mono|name(index1, index2)}} etc.
| Ada, ALGOL W, BASIC, COBOL, Fortran, RPG, GNU Octave, MATLAB, PL/I, Scala, Visual Basic, Visual Basic (.NET), Xojo |
{{Mono|$name(index)}} |
{{Mono|name.(index)}}
| OCaml |
{{Mono|name.[index]}} |
{{Mono|name/index}}
| Red |
{{Mono|name ! index}}
| Haskell |
{{Mono|$name ? index}} |
{{Mono|(vector-ref name index)}}
| Scheme |
{{Mono|(aref name index)}} |
{{Mono|(elt name index)}}
| ISLISP |
{{Mono|name{{brackets|index}}}} |
{{Mono|name at:index}} |
{{Mono|[name objectAtIndex:index]}}
| Objective-C ( |
{{Mono|index{name}}
| J |
{{Mono|name.item(index)}} or {{mono|name @ index{{Cite web|url=http://smarteiffel.loria.fr/libraries/api/lib.d/storage.d/loadpath.se.d/collection.d/ARRAY/ANY.html|title=Eiffeldoc : ARRAY}}}}
| Eiffel |
=Slicing=
The following list contains syntax examples of how a range of element of an array can be accessed.
In the following table:
- {{Mono|first}} – the index of the first element in the slice
- {{Mono|last}} – the index of the last element in the slice
- {{Mono|end}} – one more than the index of last element in the slice
- {{Mono|len}} – the length of the slice (= end - first)
- {{Mono|step}} – the number of array elements in each (default 1)
class="wikitable" |
scope="col" | Format
! scope="col" | Languages |
---|
{{Mono|name[first:last]}} |
{{Mono|name[first+(⍳len)-⎕IO]}}
| APL |
{{Mono|name[first:end:step]}}
| Python |
{{Mono|name[first:end]}}
| Go |
{{Mono|name[first..last]}}
| Pascal, Object Pascal, Delphi, Nim |
{{Mono|$name[first..last]}} |
{{Mono|@name[first..last]}}
| Perl |
{{Mono|name[first..last] name[first...end] name[first, len]}} | Ruby |
{{Mono|copy/part skip name first len}}
| Red |
{{Mono|name(first..last)}}
| Ada |
{{Mono|name(first:last)}}
| Fortran, GNU Octave, MATLAB |
{{Mono|name{{brackets|first;;last;;step}}}} |
{{Mono|name{{brackets|first:last}}}}
| S-Lang |
{{Mono|name.[first..step..last]}}
| F# |
{{Mono|name.slice(first, end)}}
| Haxe, JavaScript, Scala |
{{Mono|name.slice(first, len)}}
| CFML |
{{Mono|array_slice(name, first, len)}}
| PHP |
{{Mono|(subseq name first end)}} |
{{Mono|(subseq name first end)}}
| ISLISP |
{{Mono|Array.sub name first len}}
| OCaml |
{{Mono|[name subarrayWithRange:NSMakeRange(first, len)]}}
| Objective-C ( |
{{Mono|(first([+i.@(-~)end){name}}
| J |
{{Mono|name[first..<end] name[first...last]}} | Swift |
{{Mono|name copyFrom: first to:last name copyFrom: first count:len}} |
{{Mono|name[first..end]}} |
{{Mono|name[first..end] name[first.. | Rust |
{{Mono|name[first:end]}}
| Cobra |
table.move(name, first, last, 1, {})
| Lua{{Cite web |title=Lua 5.3 Reference Manual |url=https://www.lua.org/manual/5.3/manual.html#pdf-table.move |access-date=2022-04-02 |website=www.lua.org}} |
Array system cross-reference list
class="sortable wikitable" style="text-align: center;"
|+ ! scope="col" | Language ! scope="col" | Default ! scope="col" | Specifiable ! scope="col" | Specifiable ! scope="col" | Bound check ! scope="col" | Multidimensional ! scope="col" | Dynamically-sized ! scope="col" | Vectorized operations |
Ada
| style="background:honeydew;" | index type | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | checked | style="background:honeydew;" | yes |
ALGOL 68
| style="background:azure;" | 1 | style="background:seashell;" | no | style="background:honeydew;" | yes | style="background:cornsilk;" | varies | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:azure;" | user definable |
APL
| style="background:azure;" | 1 | style="background:grey80;" | ? | style="background:cornsilk;" | 0 or 1 | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
AWK
| style="background:azure;" | 1 | style="background:honeydew;" | yes, implicitly | style="background:seashell;" | no | style="background:seashell;" | unchecked | style="background:honeydew;" | yes, as delimited string | style="background:honeydew;" | yes, rehashed | style="background:seashell;" | no |
BASIC
| style="background:cornsilk;" | 0 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:seashell;" | no | style="background:azure;" | init | style="background:grey80;" | ? |
C
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:seashell;" | unchecked | style="background:honeydew;" | partially | style="background:lavender;" | init, heap | style="background:seashell;" | no |
Ch
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes, also array of array | style="background:lavender;" | init, heap | style="background:honeydew;" | yes |
C++
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:seashell;" | unchecked | style="background:honeydew;" | yes, also array of array | style="background:AliceBlue;" | heap | style="background:seashell;" | no |
C#
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:cornsilk;" | partial | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:AliceBlue;" | heap | style="background:honeydew;" | yes (LINQ select) |
CFML
| style="background:azure;" | 1 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes, also array of array | style="background:honeydew;" | yes | style="background:seashell;" | no |
COBOL
| style="background:azure;" | 1 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:seashell;" | no | style="background:grey80;" | some intrinsics |
Cobra
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:azure;" | heap | style="background:grey80;" | ? |
Common Lisp
| style="background:cornsilk;" | 0 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes (map or map-into) |
D
| style="background:cornsilk;" | 0 | style="background:honeydew;" | yes[http://dlang.org/hash-map.html Associative Arrays - D Programming Language] | style="background:seashell;" | no | style="background:cornsilk;" | varies | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:grey80;" | ? |
F#
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:cornsilk;" | partial | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:AliceBlue;" | heap | style="background:honeydew;" | yes (map) |
FreeBASIC
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:honeydew;" | yes | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:azure;" | init, init | style="background:grey80;" | ? |
Fortran
| style="background:azure;" | 1 | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:cornsilk;" | varies | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
FoxPro
| style="background:azure;" | 1 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:grey80;" | ? |
Go
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:seashell;" | no | style="background:seashell;" | no |
Hack
| style="background:cornsilk;" | 0 | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Haskell
| style="background:cornsilk;" | 0 | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | checked | style="background:honeydew;" | yes, also array of array | style="background:azure;" | init | style="background:grey80;" | ? |
IDL
| style="background:cornsilk;" | 0 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
ISLISP
| style="background:cornsilk;" | 0 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | init | style="background:honeydew;" | yes (map or map-into) |
J
| style="background:cornsilk;" | 0 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Java
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:azure;" | init | style="background:grey80;" | ? |
JavaScript
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Julia
| style="background:azure;" | 1 | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | checked (can be skipped locally; or globally by user) | style="background:honeydew;" | yes, also array of array | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Lingo
| style="background:azure;" | 1 | style="background:grey80;" | ? | style="background:grey80;" | ? | style="background:seashell;" | unchecked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Lua
| style="background:azure;" | 1 | style="background:grey80;" | ? | style="background:cornsilk;" | partial | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes | style="background:grey80;" | ? |
Mathematica
| style="background:azure;" | 1 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
MATLAB
| style="background:azure;" | 1 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Nim
| style="background:cornsilk;" | 0 | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | optional{{Cite web|url=https://nim-lang.org/docs/nimc.html|title = Nim Compiler User Guide}} | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes | style="background:honeydew;" | yes{{Cite web|url=https://stackoverflow.com/questions/53084192/r-style-logical-vector-operation-in-nim|title=Vectorization - R-style logical vector operation in Nim}} |
Oberon
| style="background:cornsilk;" | 0 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:seashell;" | no | style="background:grey80;" | ? |
Oberon-2
| style="background:cornsilk;" | 0 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:grey80;" | ? |
Objective-C
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes | style="background:seashell;" | no |
OCaml
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked by default | style="background:cornsilk;" | array of array | style="background:azure;" | init | style="background:grey80;" | ? |
Pascal, Object Pascal
| style="background:honeydew;" | index type | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:cornsilk;" | varies | style="background:honeydew;" | yes | style="background:cornsilk;" | varies | style="background:cornsilk;" | some |
Perl
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:honeydew;" | yes ( | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes |
Raku
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
PHP
| style="background:cornsilk;" | 0 | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
PL/I
| style="background:azure;" | 1 | style="background:grey80;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | optional | style="background:honeydew;" | yes | style="background:seashell;" | no |
Python
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes |
RPG
| style="background:azure;" | 1 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:seashell;" | no | style="background:grey80;" | ? |
R
| style="background:azure;" | 1 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:seashell;" | unchecked | style="background:honeydew;" |yes, also array of array | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Ring
| style="background:azure;" | 1 | style="background:grey80;" | ? | style="background:cornsilk;" | partial | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes | style="background:grey80;" | ? |
Ruby
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes | style="background:grey80;" | ? |
Rust
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:grey80;" | no | style="background:grey80;" | ? |
Sass
| style="background:azure;" | 1 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:azure;" | init | style="background:grey80;" | ? |
S-Lang
| style="background:cornsilk;" | 0 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Scala
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:azure;" | init | style="background:honeydew;" | yes (map) |
Scheme
| style="background:cornsilk;" | 0 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:azure;" | init | style="background:honeydew;" | yes (map) |
Smalltalk
| style="background:azure;" | 1 | style="background:grey80;" | ? | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes | style="background:grey80;" | ? |
Swift
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes | style="background:grey80;" | ? |
Visual Basic (classic)
| style="background:honeydew;" | 0, 1, or index type | style="background:seashell;" | no | style="background:honeydew;" | yes | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:grey80;" | ? |
Visual Basic (.NET)
| style="background:honeydew;" | 0 or index type | style="background:seashell;" | no | style="background:cornsilk;" | partial | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes (LINQ select) |
Wolfram Language
| style="background:azure;" | 1 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Windows PowerShell
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | heap | style="background:grey80;" | ? |
Xojo
| style="background:cornsilk;" | 0 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:honeydew;" | yes | style="background:honeydew;" | yes | style="background:seashell;" | no |
XPath/XQuery
| style="background:azure;" | 1 | style="background:seashell;" | no | style="background:seashell;" | no | style="background:honeydew;" | checked | style="background:cornsilk;" | array of array | style="background:honeydew;" | yes | style="background:honeydew;" | yes |
Vectorized array operations
Some compiled languages such as Ada and Fortran, and some scripting languages such as IDL, MATLAB, and S-Lang, have native support for vectorized operations on arrays. For example, to perform an element by element sum of two arrays, {{Mono|a}} and {{Mono|b}} to produce a third {{Mono|c}}, it is only necessary to write
c = a + b
In addition to support for vectorized arithmetic and relational operations, these languages also vectorize common mathematical functions such as sine. For example, if {{Mono|x}} is an array, then
y = sin (x)
will result in an array {{Mono|y}} whose elements are sine of the corresponding elements of the array {{Mono|x}}.
Vectorized index operations are also supported. As an example,
even = x(2::2);
odd = x(::2);
is how one would use Fortran to create arrays from the even and odd entries of an array. Another common use of vectorized indices is a filtering operation. Consider a clipping operation of a sine wave where amplitudes larger than 0.5 are to be set to 0.5. Using S-Lang, this can be done by
y = sin(x);
y[where(abs(y)>0.5)] = 0.5;
= Mathematical matrix operations =
class="wikitable" style="white-space:nowrap;"
! scope="col" | Language/ ! scope="col" | Create ! scope="col" | Determinant ! scope="col" | Transpose ! scope="col" | Element ! scope="col" | Column ! scope="col" | Row ! scope="col" | Eigenvalues |
APL
| {{code|2=apl|m←dims⍴x11 x12 ...}} | {{code|2=apl |
.×m}}
| {{code|2=apl|⍉m}} | {{code|2=apl|m[i;j]}} or {{code|2=apl|i j⌷m}} | {{code|2=apl|m[;j]}} or {{code|2=apl|j⌷[2]m}} or | {{code|2=apl|m[i;]}} or {{code|2=apl|i⌷m}} | {{code|2=apl|⌹⍠1⊢m}} |
Fortran
| {{code|1=m = RESHAPE([x11, x12, ...], SHAPE(m))}} | | {{code|TRANSPOSE(m)}} | {{code|m(i,j)}} | {{code|m(:,j)}} | {{code|m(i,:)}} | |
Ch[http://www.softintegration.com/products/features/ch_vs_matlab.html Ch numerical features]
| {{code|1=m = {...}}} | {{code|determinant(m)}} | {{code|transpose(m)}} | {{code|m[i-1][j-1]}} | {{code|shape(m,0)}} | {{code|shape(m,1)}} | {{code|eigen(output, m, NULL)}} |
Julia and its standard library {{code|LinearAlgebra}} | {{code|lang=julia|code=m = [1 2; 3 4]}} or m = [ 1 2 3 4 ] | {{code|lang=julia|det(m)}} | {{code|lang=julia|transpose(m)}} or {{code|lang=julia|m'}} for real matrices | {{code|lang=julia|m[i, j]}} | {{code|lang=julia|m[:, j]}} | {{code|lang=julia|m[i, :]}} | {{code|lang=julia|eigen(m).values}} |
Mathematica / Wolfram Language | | {{code|Det[m]}} | {{code|Transpose[m]}} | {{code|mi,j}} | {{code|m;;,j}} | {{code|mi}} | {{code|Eigenvalues[m]}} |
MATLAB / GNU Octave | {{code|1=m = [...]}} | {{code|det(m)}} | {{code|m.'}} | {{code|m(i,j)}} | {{code|m(:,j)}} | {{code|m(i,:)}} | {{code|eig(m)}} |
NumPy
| {{code|1=m = mat(...)}} | {{code|linalg.det(m)}} | {{code|m.T}} | {{code|m[i-1,j-1]}} | {{code|m[:,j-1]}} | {{code|m[i-1,:]}} | {{code|linalg.eigvals(m)}} |
R
| {{code|1=m <- matrix(...)}} or {{code|1=m <- array(...)}} | {{code|det(m)}} | {{code|t(m)}} | {{code|m[i, j]}} | {{code|m[, j]}} | {{code|m[i, ]}} | {{code|eigen(m)}} |
S-Lang
| {{code|1=m = reshape([x11, x12, ...], [new-dims])}} | | {{code|1=m = transpose(m)}} | {{code|m[i,j]}} | {{code|m[*,j]}} | {{code|m[j,*]}} | |
SymPy
| {{code|1=m = Matrix(...)}} | {{code|m.det()}} | {{code|m.T}} | {{code|m[i-1,j-1]}} | {{code|m.col(j-1)}} | {{code|m.row(i-1)}} | {{code|m.eigenvals()}} |
References
{{Reflist|refs=
Slices for multidimensional arrays are also supported and defined similarly.
Slices of the type first:last:step
are also supported.
More generally, for 1-d arrays Perl and S-Lang allow slices of the formarray[indices]
, where indices
can be a range such mentioned in footnote 2 or an explicit list of indices, e.g., '[0,9,3,4]
', or a mix of both, e.g., A[0:3,7,9,[11:2:-3]]]
.
C# 8.0 proposed feature ({{as of|2019|08|29|lc=y}})
Size can only be chosen on initialization after which it is fixed.
This list is strictly comparing language features. In every language (even assembly language) it is possible to provide improved array handling via add on libraries. This language has improved array handling as part of its standard library
The class Array is fixed-size, but OrderedCollection is dynamic
At least 2 dimensions (scalar numbers are 1×1 arrays, vectors are 1×n or n×1 arrays).
Allows creating fixed-size arrays in "unsafe" code, allowing enhanced interoperability with other language
Varies by implementation. Newer implementations (Free Pascal, Object Pascal (Delphi)) allow heap-based dynamic arrays.
Many implementations (Turbo Pascal, Object Pascal (Delphi), Free Pascal) allow the behaviour to be changed by compiler switches and in-line directives
Most Common Lisp implementations allow checking to be selectively disabled
The index type can be a freely chosen integer type, enumerated type, or character type. For arrays with non-compact index types see: Associative array
The default base index is the lowest value of the index type used
Standard Perl array data types do not support vectorized operations as defined here. However, the Perl Data Language extension adds array objects with this ability.
The standard Python array type, list
, does not support vectorized operations as defined here. However, the numpy extension adds array objects with this ability
COBOL arrays may be indexed with "INDEX" types, distinct from integer types
Size can be chosen when the array is declared, or when it is allocated, after which it is fixed.
The base can be changed when initializing with {{Mono|System.Array.CreateInstance}} (which returns {{Mono|System.Array}}), but not when using the language syntax. Arrays with non-zero base indices are not the same type as those with zero base indices and cannot be manipulated using language syntax (the {{Mono|GetValue}} and {{Mono|SetValue}} methods must be used instead) or downcast to a specific type ({{Mono|T[]}} in C#, or {{Mono|T()}} in VB.NET), preventing breakage of code assuming base indices of zero.
Microsoft QBASIC, QuickBASIC, Visual Basic, and VBA all had/have the ability to specify Option Base 1, which caused all arrays in the module to default starting at 1 instead of 0. Support for Option Base was phased out in Visual Basic (.NET). In various Microsoft BASIC implementations, arrays can be DIMensioned using to to specify the minimum and maximum index values (e.g. {{Mono|DIM MyArray(2 to 50) AS STRING}} would have the first index at 2 instead of the default).
}}