-
Notifications
You must be signed in to change notification settings - Fork 0
happy.ndarray
Jan Kukačka edited this page Mar 9, 2022
·
1 revision
N-D array manipulation
Convert matrix represented by the last 2 axes of an array to 1D array containing the diagonal of the matrix, leave preceding dimensions unchanged.
-
array
: numpy array of shape [..., N, N]
-
array
: numpy array of shape [..., N] with elements of the diagonal of the last 2 dimensions in the last dimension
collapse_diag(np.array([[[1, 0, 0],
[0, 2, 0],
[0, 0, 3]],
[[4, 0, 0],
[0, 5, 0],
[0, 0, 6]]]))
[[1,2,3],
[4,5,6]]
Convert last axis of an array to a diagonal matrix, leave preceding dimensions unchanged.
-
array
: numpy array of shape [..., N]
-
array
: numpy array of shape [..., N, N] with elements of the input array on the diagonal of the last 2 dimensions
diag(np.array([[1,2,3],
[4,5,6]]))
[[[1, 0, 0],
[0, 2, 0],
[0, 0, 3]],
[[4, 0, 0],
[0, 5, 0],
[0, 0, 6]]]