This comparison of programming languages (array) compares the features of array data structures or matrix processing for over 48 various computer programming languages.
Contents
Array dimensions
The following list contains syntax examples of how to determine the dimensions (index of the first element, the last element and/or the size in elements).
Note particularly that some languages index from zero while others index from one. At least since Dijkstra's famous essay, zero-based indexing has been seen as superior, and new languages tend to use it.
Indexing
The following list contains syntax examples of how to access a single element of an array.
Slicing
The following list contains syntax examples of how a range of element of an array can be accessed.
In the following table:
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, a and b to produce a third c, it is only necessary to write
c = a + bIn addition to support for vectorized arithmetic and relational operations, these languages also vectorize common mathematical functions such as sine. For example, if x is an array, then
y = sin (x)will result in an array y whose elements are sine of the corresponding elements of the array x.
Vectorized index operations are also supported. As an example,
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;