generate functionFri, 10 Feb 2023

The input is a natural number n — the number of rows and columns in the square matrix. Next, the elements of the matrix are entered line by line with a space. Draw the maximum element below the main diagonal. The elements of the main diagonal are also taken into account.

import numpy as np def max_under_diagonal(a): n = len(a) max_elem = a[0][1] for i in range(n): for j in range(i+1, n): max_elem = max(max_elem, a[i][j]) return max_elem a = np.random.randint(0, 10, size=(3,3)) a = np.array([[1,2,3],[4,5,6],[7,8,9]]) print(max_under_diagonal(a))

Questions about programming?Chat with your personal AI assistant