This is a pre-release version (latest). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / ma / extras / diagflat

function

numpy.ma.extras:diagflat

source: build-install/usr/lib/python3.14/site-packages/numpy/lib/_twodim_base_impl.py :331

Signature

def   diagflat ( v k = 0 )

Summary

Create a two-dimensional array with the flattened input as a diagonal.

Parameters

v : array_like

Input data, which is flattened and set as the k-th diagonal of the output.

k : int, optional

Diagonal to set; 0, the default, corresponds to the "main" diagonal, a positive (negative) k giving the number of the diagonal above (below) the main.

Returns

out : ndarray

The 2-D output array.

Notes

The function is applied to both the _data and the _mask, if any.

Examples

import numpy as np
np.diagflat([[1,2], [3,4]])
np.diagflat([1,2], 1)

See also

diag

MATLAB work-alike for 1-D and 2-D arrays.

diagonal

Return specified diagonals.

trace

Sum along diagonals.

Aliases

  • numpy.ma.diagflat