chainerx.diag

chainerx.diag(v, k=0, device=None)

Returns a diagonal or a diagonal array.

Parameters
  • v (ndarray) – Array object.

  • k (int) – Index of diagonals. Zero indicates the main diagonal, a positive value an upper diagonal, and a negative value a lower diagonal.

  • device (Device) – Device on which the array is allocated. If omitted, the default device is chosen.

Returns

If v is a 1-D array, then it returns a 2-D array with the specified diagonal filled by v. If v is a 2-D array, then it returns the specified diagonal of v. In latter case, if v is a chainerx.ndarray object, then its view is returned.

Return type

ndarray

Note

The argument v does not support array-like objects yet.

See also

numpy.diag()