nums.numpy.diag
nums.numpy.diag#
- nums.numpy.diag(v: nums.core.array.blockarray.BlockArray, k=0) nums.core.array.blockarray.BlockArray#
Extract a diagonal or construct a diagonal array.
This docstring was copied from numpy.diag.
Some inconsistencies with the NumS version may exist.
See the more detailed documentation for
numpy.diagonalif you use this function to extract a diagonal and wish to write to the resulting array; whether it returns a copy or a view depends on what version of numpy you are using.- vBlockArray
If v is a 2-D array, return a copy of its k-th diagonal. If v is a 1-D array, return a 2-D array with v on the k-th diagonal.
- kint, optional
Diagonal in question. The default is 0. Use k>0 for diagonals above the main diagonal, and k<0 for diagonals below the main diagonal.
- outBlockArray
The extracted diagonal or constructed diagonal array.
diagonal : Return specified diagonals. trace : Sum along diagonals. triu : Upper triangle of an array.
offset != 0 is currently not supported.
out is currently not supported.
axis1 != 0 or axis2 != 1 is currently not supported.
The doctests shown below are copied from NumPy. They won’t show the correct result until you operate
get().>>> x = nps.arange(9).reshape((3,3)) >>> x.get() array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
>>> nps.diag(x).get() array([0, 4, 8])
>>> nps.diag(nps.diag(x)).get() array([[0, 0, 0], [0, 4, 0], [0, 0, 8]])