flopscope.numpy.diagflat
fnp.diagflat(v, k=0)[flopscope source][numpy source]
Create a two-dimensional array with the flattened input as a diagonal.
Adapted from NumPy docs np.diagflat
Cost
per-operation
Flopscope Context
Create diagonal array from flattened input. Cost: len(v).
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)
kgiving the number of the diagonal above (below) the main.
Returns
- out:ndarray
The 2-D output array.
See also
- we.flops.diag MATLAB work-alike for 1-D and 2-D arrays.
- we.flops.diagonal Return specified diagonals.
- we.flops.trace Sum along diagonals.
Examples
>>> import flopscope.numpy as fnp
>>> flops.diagflat([[1,2], [3,4]])
array([[1, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 3, 0],
[0, 0, 0, 4]])>>> flops.diagflat([1,2], 1)
array([[0, 1, 0],
[0, 0, 2],
[0, 0, 0]])