Generation

generate functionTue, 10 Jan 2023

Create in Numpy a diagonal matrix with elements from N to 0. Count the sum of its values on the diagonal.

import numpy as np def diagonal_matrix(n): arr = np.arange(1, n+1) return np.diag(arr) print(diagonal_matrix(4))

Questions about programming?Chat with your personal AI assistant