Skip to content

Ones

Description

Ones returns a matrix of all ones with the desired shape, which is useful for linear algebra applications. This is a helper function used in a variety of other CLS-Stats regression functions.

Syntax

Ones([numrows=1], [numcols=1]) where numrows and numcols are the desired number of rows and columns in the output.

Example

Ones examples: Ones(3) gives a column of three 1s, Ones(,3) a row of three, and Ones(3,5) a 3x5 matrix of 1s

Source Code

Ones = LAMBDA([numrows], [numcols], //input rows and columns
    LET(
        numrows, IF(ISOMITTED(numrows), 1, numrows), // default r=1
        numcols, IF(ISOMITTED(numcols), 1, numcols), // default c=1
        EXPAND(1, numrows, numcols, 1)
    )
);