Skip to content

Allow diagm(v) for a vector v #609

Closed
@dpsanders

Description

@dpsanders

It would be useful to allow diagm(v) for a vector v, for the common case of wanting that vector on the main diagonal:

julia> using LinearAlgebra

julia> v = [3, 4]
2-element Array{Int64,1}:
 3
 4

julia> diagm(v)
ERROR: MethodError: no method matching diagm(::Array{Int64,1})
Closest candidates are:
  diagm(::Pair{#s623,#s622} where #s622<:(AbstractArray{T,1} where T) where #s623<:Integer...) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/LinearAlgebra/src/dense.jl:291
Stacktrace:
 [1] top-level scope at none:0

julia> diagm(0=>v)
2×2 Array{Int64,2}:
 3  0
 0  4

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsgood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions