Comparison of programming languages (array): Difference between revisions

Content deleted Content added
Line 875:
 
Some compiled languages such as [[Ada (programming language)|Ada]] and [[Fortran]], and some scripting languages such as [[IDL (programming language)|IDL]], [[MATLAB]], and [[S-Lang (programming library)|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}}.
Line 884:
Vectorized index operations are also supported. As an example,
<syntaxhighlight lang="fortran">
even = x(2::2);
odd = x(::2);
</syntaxhighlight>
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 (programming library)|S-Lang]], this can be done by
y = sin(x);
y[where(abs(y)>0.5)] = 0.5;
 
=== Mathematical matrix operations ===