docs/reference/classes/matrixindex.md
<a name="Index"></a>
<a name="new_Index_new"></a>
Create an index. An Index can store ranges and sets for multiple dimensions. Matrix.get, Matrix.set, and math.subset accept an Index as input.
Usage:
const index = new Index(range1, range2, matrix1, array1, ...)
Where each parameter can be any of:
The parameters start, end, and step must be integer numbers.
| Param | Type |
|---|---|
| ...ranges | <code>*</code> |
<a name="Index+valueOf"></a>
Get the primitive value of the Index, a two dimensional array. Equivalent to Index.toArray().
Kind: instance property of <code>Index</code>
Returns: <code>Array</code> - array
<a name="Index+clone"></a>
Create a clone of the index
Kind: instance method of <code>Index</code>
Returns: <code>Index</code> - clone
<a name="Index+size"></a>
Retrieve the size of the index, the number of elements for each dimension.
Kind: instance method of <code>Index</code>
Returns: <code>Array.<number></code> - size
<a name="Index+max"></a>
Get the maximum value for each of the indexes ranges.
Kind: instance method of <code>Index</code>
Returns: <code>Array.<number></code> - max
<a name="Index+min"></a>
Get the minimum value for each of the indexes ranges.
Kind: instance method of <code>Index</code>
Returns: <code>Array.<number></code> - min
<a name="Index+forEach"></a>
Loop over each of the ranges of the index
Kind: instance method of <code>Index</code>
| Param | Type | Description |
|---|---|---|
| callback | <code>function</code> | Called for each range with a Range as first argument, the dimension as second, and the index object as third. |
<a name="Index+dimension"></a>
Retrieve the dimension for the given index
Kind: instance method of <code>Index</code>
Returns: <code>Range</code> | <code>null</code> - range
| Param | Type | Description |
|---|---|---|
| dim | <code>Number</code> | Number of the dimension |
<a name="Index+isScalar"></a>
Test whether this index contains only a single value.
This is the case when the index is created with only scalar values as ranges, not for ranges resolving into a single value.
Kind: instance method of <code>Index</code>
Returns: <code>boolean</code> - isScalar
<a name="Index+toArray"></a>
Expand the Index into an array. For example new Index([0,3], [2,7]) returns [[0,1,2], [2,3,4,5,6]]
Kind: instance method of <code>Index</code>
Returns: <code>Array</code> - array
<a name="Index+toString"></a>
Get the string representation of the index, for example '[2:6]' or '[0:2:10, 4:7, [1,2,3]]'
Kind: instance method of <code>Index</code>
Returns: <code>String</code> - str
<a name="Index+toJSON"></a>
Get a JSON representation of the Index
Kind: instance method of <code>Index</code>
Returns: <code>Object</code> - Returns a JSON object structured as:
{"mathjs": "Index", "ranges": [{"mathjs": "Range", start: 0, end: 10, step:1}, ...]}
<a name="Index.fromJSON"></a>
Instantiate an Index from a JSON object
Kind: static method of <code>Index</code>
| Param | Type | Description |
|---|---|---|
| json | <code>Object</code> | A JSON object structured as: {"mathjs": "Index", "dimensions": [{"mathjs": "Range", start: 0, end: 10, step:1}, ...]} |