ones

ones(m)

ones(m, n)

ones(m, n, p, ...)

ones([m])

ones([m, n])

ones([m, n, p, ...])

Try it yourself:


ones(): create a matrix filled with one

ones(n), or ones with dimensions, creates an array or matrix whose entries are all 1. It is a convenient starting point for weights, offsets, test fixtures, and matrix formulas.

Examples

ones(3) creates a length-three vector of ones; supplying two dimensions creates a rectangular matrix. Add or multiply it with another matrix when every position needs the same adjustment.

Matrix companions

Use zeros() for a zero-filled structure, identity() for an identity matrix, and size() to verify shape. Combine with multiply() or add() in matrix expressions.

Shape matters

Dimensions should be non-negative integers. Match shapes before elementwise operations to avoid broadcasting or dimension errors.

Try Ones in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions