mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
1.1 KiB
1.1 KiB
Function ones
Create a matrix filled with ones. The created matrix can have one or multiple dimensions.
Syntax
math.ones(m)
math.ones(m, format)
math.ones(m, n)
math.ones(m, n, format)
math.ones([m, n])
math.ones([m, n], format)
math.ones([m, n, p, ...])
math.ones([m, n, p, ...], format)
Parameters
| Parameter | Type | Description |
|---|---|---|
size |
...number | Array | The size of each dimension of the matrix |
format |
string | The Matrix storage format |
Returns
| Type | Description |
|---|---|
| Array | Matrix | number | A matrix filled with ones |
Examples
math.ones(3); // returns [1, 1, 1]
math.ones(3, 2); // returns [[1, 1], [1, 1], [1, 1]]
math.ones(3, 2, 'dense'); // returns Dense Matrix [[1, 1], [1, 1], [1, 1]]
var A = [[1, 2, 3], [4, 5, 6]];
math.ones(math.size(A)); // returns [[1, 1, 1], [1, 1, 1]]