cupy.diag#

cupy.diag(v, k=0)[source]#

Returns a diagonal or a diagonal array.

Parameters:
  • v (array-like) – Array or array-like object.

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

Returns:

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

Return type:

cupy.ndarray

See also

numpy.diag()