Difference between revisions of "Array-reducing functions"

Line 4: Line 4:
 
__TOC__
 
__TOC__
  
An array-reducing function operates across a dimension of an array and returns a result that has one dimension less than the number of dimensions of its input array. When applied to an array of <code>n</code> dimensions, a reducing function produces an array that contains <code>n-1</code> dimensions. Examples include, '''Sum(x, i)''', Product(x,i), Max(x, i), Min(x, i)''', and others described below. The subscript construct '''x[i = v]''' and related subscript and slice functions also reduce arrays by a dimension (see [[Subscript and slice of a subarray]]).
+
An array-reducing function operates across a dimension of an array and returns a result that has one dimension less than the number of dimensions of its input array. When applied to an array of <code>n</code> dimensions, a reducing function produces an array that contains <code>n-1</code> dimensions. Examples include, '''Sum(x, i), Product(x,i), Max(x, i), Min(x, i)''', and others described below. The subscript construct '''x[i = v]''' and related subscript and slice functions also reduce arrays by a dimension (see [[Subscript and slice of a subarray]]).
  
 
The function '''Sum(x, i)''' illustrates some properties of reducing functions.
 
The function '''Sum(x, i)''' illustrates some properties of reducing functions.
Line 12: Line 12:
 
<code>Sum(Car_prices, Car_type) →</code>
 
<code>Sum(Car_prices, Car_type) →</code>
  
<code>Variable Rate_of_inflation :=</code>
 
 
{| class=''wikitable'' border="1"  
 
{| class=''wikitable'' border="1"  
! colspan="5" style="text-align: left;" | Years &#9654;
+
! colspan="5" | Years &#9654;
 
|-
 
|-
 
! style="width:75px;" |'''2005            '''
 
! style="width:75px;" |'''2005            '''
Line 28: Line 27:
 
| 76K
 
| 76K
 
|}
 
|}
 +
 +
<code>Sum(Car_prices, Years) →</code>
 +
 +
{| class=''wikitable'' border="1"
 +
! colspan="3" | Car_type &#9654;
 +
|-
 +
! style="width:75px;" |'''VW            '''
 +
! style="width:75px;" |'''Honda          '''
 +
! style="width:75px;" |'''BMW          '''
 +
|-
 +
| 99K
 +
| 103K
 +
| 141K
 +
|}
 +
 +
<code>Sum(Sum(Car_prices, Years), Car_type) → 334K</code>
 +
 +
See [[Array Function Example Variables]] for example array variables used here and below.
 +
 +
<tip title="Tip">The second parameter, '''i''', specifying the dimension over which to sum, is optional. But if the array, '''x''', has more than one dimension, Analytica might not sum over the dimension you expect. For this reason, it is safer always to specify the dimension index explicitly in '''Sum()''' or any other array-reducing function.</Tip>
 +
 +
  
 
==See Also==
 
==See Also==
 
<footer>Functions that create arrays / {{PAGENAME}} / Transforming functions</footer>
 
<footer>Functions that create arrays / {{PAGENAME}} / Transforming functions</footer>

Revision as of 03:20, 11 December 2015

An array-reducing function operates across a dimension of an array and returns a result that has one dimension less than the number of dimensions of its input array. When applied to an array of n dimensions, a reducing function produces an array that contains n-1 dimensions. Examples include, Sum(x, i), Product(x,i), Max(x, i), Min(x, i), and others described below. The subscript construct x[i = v] and related subscript and slice functions also reduce arrays by a dimension (see Subscript and slice of a subarray).

The function Sum(x, i) illustrates some properties of reducing functions.

Examples

Sum(Car_prices, Car_type) →

Years ▶
2005 2006 2007 2008 2009
59K 62K 66K 71K 76K

Sum(Car_prices, Years) →

Car_type ▶
VW Honda BMW
99K 103K 141K

Sum(Sum(Car_prices, Years), Car_type) → 334K

See Array Function Example Variables for example array variables used here and below.

Tip
The second parameter, i, specifying the dimension over which to sum, is optional. But if the array, x, has more than one dimension, Analytica might not sum over the dimension you expect. For this reason, it is safer always to specify the dimension index explicitly in Sum() or any other array-reducing function.


See Also

Comments


You are not allowed to post comments.