UNPKG

1.14 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function identity
4
5Create a 2-dimensional identity matrix with size m x n or n x n.
6The matrix has ones on the diagonal and zeros elsewhere.
7
8
9## Syntax
10
11```js
12math.identity(n)
13math.identity(n, format)
14math.identity(m, n)
15math.identity(m, n, format)
16math.identity([m, n])
17math.identity([m, n], format)
18```
19
20### Parameters
21
22Parameter | Type | Description
23--------- | ---- | -----------
24`size` | ...number &#124; Matrix &#124; Array | The size for the matrix
25`format` | string | The Matrix storage format
26
27### Returns
28
29Type | Description
30---- | -----------
31Matrix &#124; Array &#124; number | A matrix with ones on the diagonal.
32
33
34## Examples
35
36```js
37math.identity(3) // returns [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
38math.identity(3, 2) // returns [[1, 0], [0, 1], [0, 0]]
39
40const A = [[1, 2, 3], [4, 5, 6]]
41math.identity(math.size(A)) // returns [[1, 0, 0], [0, 1, 0]]
42```
43
44
45## See also
46
47[diag](diag.md),
48[ones](ones.md),
49[zeros](zeros.md),
50[size](size.md),
51[range](range.md)