bayespy.utils.misc.diag¶
- bayespy.utils.misc.diag(X, ndim=1)[source]¶
Create a diagonal array given the diagonal elements.
The diagonal array can be multi-dimensional. By default, the last axis is transformed to two axes (diagonal matrix) but this can be changed using ndim keyword. For instance, an array with shape (K,L,M,N) can be transformed to a set of diagonal 4-D tensors with shape (K,L,M,N,M,N) by giving ndim=2. If ndim=3, the result has shape (K,L,M,N,L,M,N), and so on.
Diagonality means that for the resulting array Y holds: Y[…,i_1,i_2,..,i_ndim,j_1,j_2,..,j_ndim] is zero if i_n!=j_n for any n.