函数索引 #
创建一个索引。一个 Index 可以存储具有多个维度的 start、step 和 end 的范围。Matrix.get、Matrix.set 和 math.subset 接受 Index 作为输入。
Syntax #
math.index(range1, range2, ...)
Where #
- 一个数字
- 用于获取/设置对象属性的字符串
- 一个
Range实例 - 一个包含数字或布尔值的一维数组或矩阵
Parameters #
| Parameter | Type | Description |
|---|---|---|
范围 |
… | 零个或多个范围或数字。 |
Returns #
| Type | Description |
|---|---|
| Index | 返回创建的索引 |
Throws #
Type | Description —- | ———–
Examples #
const b = [1, 2, 3, 4, 5]
math.subset(b, math.index([1, 2, 3])) // returns [2, 3, 4]
math.subset(b, math.index([false, true, true, true, false])) // returns [2, 3, 4]
const a = math.matrix([[1, 2], [3, 4]])
a.subset(math.index(0, 1)) // returns 2
a.subset(math.index(0, [false, true])) // returns 2