Write a NumPy program to create a 2-D array whose diagonal equals [4, 5, 6, 8] and 0's elsewhere.
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]]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer