UNPKG

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