larray.eye

larray.eye(rows, columns=None, k=0, title=None, dtype=None, meta=None)[source]

Returns a 2-D array with ones on the diagonal and zeros elsewhere.

Parameters
rowsint or Axis

Rows of the output.

columnsint or Axis, optional

Columns of the output. If None, defaults to rows.

kint, optional

Index of the diagonal: 0 (the default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.

titlestr, optional

Deprecated. See ‘meta’ below.

dtypedata-type, optional

Data-type of the returned array. Defaults to float.

metalist of pairs or dict or OrderedDict or Metadata, optional

Metadata (title, description, author, creation_date, …) associated with the array. Keys must be strings. Values must be of type string, int, float, date, time or datetime.

Returns
LArray of shape (rows, columns)

An array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to one.

Examples

>>> eye(2, dtype=int)
{0}*\{1}*  0  1
        0  1  0
        1  0  1
>>> sex = Axis('sex=M,F')
>>> eye(sex)
sex\sex    M    F
      M  1.0  0.0
      F  0.0  1.0
>>> age = Axis('age=0..2')
>>> eye(age, sex)
age\sex    M    F
      0  1.0  0.0
      1  0.0  1.0
      2  0.0  0.0
>>> eye(3, k=1)
{0}*\{1}*    0    1    2
        0  0.0  1.0  0.0
        1  0.0  0.0  1.0
        2  0.0  0.0  0.0