Skip to content

Commit 799ca1a

Browse files
authored
Add diagm example (#1298)
Add an example for the method `diagm(m, n, v)`, and clarify that zero-padding may be used for larger matrices.
2 parents a145117 + 537ee46 commit 799ca1a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/dense.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ Construct a matrix with elements of the vector as diagonal elements.
399399
By default, the matrix is square and its size is given by
400400
`length(v)`, but a non-square size `m`×`n` can be specified
401401
by passing `m,n` as the first arguments.
402+
The diagonal will be zero-padded if necessary.
402403
403404
# Examples
404405
```jldoctest
@@ -407,6 +408,13 @@ julia> diagm([1,2,3])
407408
1 0 0
408409
0 2 0
409410
0 0 3
411+
412+
julia> diagm(4, 5, [1,2,3])
413+
4×5 Matrix{Int64}:
414+
1 0 0 0 0
415+
0 2 0 0 0
416+
0 0 3 0 0
417+
0 0 0 0 0
410418
```
411419
"""
412420
diagm(v::AbstractVector) = diagm(0 => v)

0 commit comments

Comments
 (0)