larray.eye¶
-
larray.eye(rows, columns=None, k=0, title='', dtype=None)[source]¶ Returns a 2-D array with ones on the diagonal and zeros elsewhere.
Parameters: rows : int or Axis
Rows of the output.
columns : int or Axis, optional
Columns of the output. If None, defaults to rows.
k : int, 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.
title : str, optional
Title.
dtype : data-type, optional
Data-type of the returned array. Defaults to float.
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