numpy -Create a 4 x 4 matrix and add values 4,5,6 above the parent diagonal

Create a 4 x 4 matrix and add values 4,5,6 above the parent diagonal.I'm unable to understand how to achieve this output. Tried diagonal method but failed. I want the output as shown below.

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


Read more here: https://stackoverflow.com/questions/53910902/numpy-create-a-4-x-4-matrix-and-add-values-4-5-6-above-the-parent-diagonal

Content Attribution

This content was originally published by Chandan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: