Skip to content

np.diag() - Create a diagonal matrix #34

Description

@sahil3028

Syntax:
np.diag(v, k=0)

Arguments:
v: 1D array (to form diagonal) or 2D matrix.
k: Diagonal shift.

Example:
diag_matrix = np.diag([1, 2, 3])

[[1 0 0]
[0 2 0]
[0 0 3]]

diag_shifted = np.diag([4, 5, 6], k=1)

[[0 4 0 0]
[0 0 5 0]
[0 0 0 6]
[0 0 0 0]]

Note: we cant solve this issue rn we need help to take arguments like this -p.diag([4, 5, 6], k=1)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions