Q:

Write a NumPy program to get a copy of a matrix with the elements below the k-th diagonal zeroed

0

Write a NumPy program to get a copy of a matrix with the elements below the k-th diagonal zeroed.

All Answers

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

import numpy as np
result  = np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1)
print("\nCopy of a matrix with the elements below the k-th diagonal zeroed:")
print(result)

Sample Output:

Copy of a matrix with the elements below the k-th diagonal zeroed:
[[ 1  2  3]
 [ 4  5  6]
 [ 0  8  9]
 [ 0  0 12]]

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