numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
diag(v, k=0)

See the more detailed documentation for numpy.diagonal if 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.

Parameters

v : array_like

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.

k : int, optional

Diagonal in question. The default is 0. Use :None:None:`k>0` for diagonals above the main diagonal, and :None:None:`k<0` for diagonals below the main diagonal.

Returns

out : ndarray

The extracted diagonal or constructed diagonal array.

Extract a diagonal or construct a diagonal array.

See Also

diagflat

Create a 2-D array with the flattened input as a diagonal.

diagonal

Return specified diagonals.

trace

Sum along diagonals.

tril

Lower triangle of an array.

triu

Upper triangle of an array.

Examples

>>> x = np.arange(9).reshape((3,3))
... x array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
>>> np.diag(x)
array([0, 4, 8])
>>> np.diag(x, k=1)
array([1, 5])
>>> np.diag(x, k=-1)
array([3, 7])
>>> np.diag(np.diag(x))
array([[0, 0, 0],
       [0, 4, 0],
       [0, 0, 8]])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

dask.array.routines.fliplr dask.array.routines.flipud numpy.ma.extras.diagflat scipy.linalg._decomp_qr.qr scipy.optimize._optimize.fmin_bfgs numpy.compress numpy.diagonal numpy.diagflat scipy.linalg._decomp_svd.svd numpy.select scipy.linalg._decomp_cholesky.cholesky_banded dask.array.routines.apply_along_axis dask.array.creation.diag scipy.linalg._decomp.eig_banded scipy.sparse.linalg._eigen._svds.svds scipy.sparse._construct.diags scipy.linalg._decomp_cholesky.cho_solve_banded dask.array.einsumfuncs.einsum numpy.trace numpy.eye numpy.ma.core.diag scipy.linalg._decomp.eigh

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/lib/twodim_base.py#234
type: <class 'function'>
Commit: