I am trying to take a diagonal matrix but unfortunately, I am getting an error. My code is:
import numpy as np
a = np.array([1, 2, 3, 2, 1 ,2])
b = np.diagonal((a)*(a).T)
I am trying to take a diagonal matrix but unfortunately, I am getting an error. My code is:
import numpy as np
a = np.array([1, 2, 3, 2, 1 ,2])
b = np.diagonal((a)*(a).T)
Try
import numpy as np
a = np.array([1, 2, 3, 2, 1 ,2])[np.newaxis]
b = np.diagonal((a)*(a).T)
Refer: Transposing a 1D NumPy array
Or you could do:
import numpy as np
a = np.array([1, 2, 3, 2, 1 ,2]).reshape(1,-1)
b = np.diagonal((a)*(a).T)
The goal is to make this into a matrix of two dimensions rather than a one dimensional array as it was originally declared.