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