bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / diagflat
_ArrayFunctionDispatcher
numpy:diagflat
source: /dev/numpy/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_likeInput data, which is flattened and set as the
k-th diagonal of the output.k: int, optionalDiagonal to set; 0, the default, corresponds to the "main" diagonal, a positive (negative)
kgiving the number of the diagonal above (below) the main.
Returns
out: ndarrayThe 2-D output array.
Examples
import numpy as np np.diagflat([[1,2], [3,4]])✓
array([[1, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 3, 0],
[0, 0, 0, 4]])
np.diagflat([1,2], 1)
✓array([[0, 1, 0],
[0, 0, 2],
[0, 0, 0]])
See also
Aliases
numpy.diagflat