Convert a 1D vector into a diagonal matrix. Given a list or 1D array of values, return a 2D square matrix with those values on the main diagonal and zeros elsewhere.
import numpy as np
def make_diagonal(vector):
n = len(vector)
matrix = np.zeros((n, n))
for i in range(n):
matrix[i][i] = vector[i]
return matrix.tolist()n of the input vector.n x n zero matrix.matrix[i][i] to the corresponding vector value.