Write a NumPy program to set zero to lower triangles along the last two axes of a three-dimensional of a given array.
import numpy as np arra=np.ones((1,8,8)) print("Original array:") print(arra) result = np.triu(arra, k=1) print("\nResult:") print(result)
Sample Output:
Original array: [[[1. 1. 1. 1. 1. 1. 1. 1.] [1. 1. 1. 1. 1. 1. 1. 1.] [1. 1. 1. 1. 1. 1. 1. 1.] [1. 1. 1. 1. 1. 1. 1. 1.] [1. 1. 1. 1. 1. 1. 1. 1.] [1. 1. 1. 1. 1. 1. 1. 1.] [1. 1. 1. 1. 1. 1. 1. 1.] [1. 1. 1. 1. 1. 1. 1. 1.]]] Result: [[[0. 1. 1. 1. 1. 1. 1. 1.] [0. 0. 1. 1. 1. 1. 1. 1.] [0. 0. 0. 1. 1. 1. 1. 1.] [0. 0. 0. 0. 1. 1. 1. 1.] [0. 0. 0. 0. 0. 1. 1. 1.] [0. 0. 0. 0. 0. 0. 1. 1.] [0. 0. 0. 0. 0. 0. 0. 1.] [0. 0. 0. 0. 0. 0. 0. 0.]]]
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