larray.eye
- larray.eye(rows, columns=None, k=0, title=None, dtype=None, meta=None) Array [source]
Return a 2-D array with ones on the diagonal and zeros elsewhere.
- Parameters
- rowsint or Axis or tuple or length 2 AxisCollection
Rows of the output (if int or Axis) or rows and columns (if tuple or AxisCollection).
- columnsint or Axis, optional
Columns of the output. Defaults to the value of rows if it is an int or Axis.
- 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 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
- Array 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('sex=M,F') sex\sex M F M 1.0 0.0 F 0.0 1.0 >>> eye(2, dtype=int) {0}*\{1}* 0 1 0 1 0 1 0 1 >>> age = Axis('age=0..2') >>> sex = Axis('sex=M,F') >>> 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