Q:

Write a NumPy program to create a 2-D array whose diagonal equals [4, 5, 6, 8] and 0's elsewhere

0

Write a NumPy program to create a 2-D array whose diagonal equals [4, 5, 6, 8] and 0's elsewhere.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x =  np.diagflat([4, 5, 6, 8])
print(x)

Sample Output:

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now