After a projection I need to create a multidim array with contiguous diagonal values on base of a 1D array, e.g. with some kind of multiplication with a multidim identity array. The following is just a small example for the concept. As the real data from a projection result will be a lot larger than the following 12 values example input data I need an efficient way for the data handling. (Projection problem: The original "compact" axes cannot be used anymore but the data values are still the same)
Input:
>>> a=np.arange(1,13)
array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.])
>>>a.shape
(12,)
Required Output:
array([[[ 1., 0., 0., 0.],
[ 0., 2., 0., 0.],
[ 0., 0., 3., 0.],
[ 0., 0., 0., 4.]],
[[ 5., 0., 0., 0.],
[ 0., 6., 0., 0.],
[ 0., 0., 7., 0.],
[ 0., 0., 0., 8.]],
[[ 9., 0., 0., 0.],
[ 0., 10., 0., 0.],
[ 0., 0., 11., 0.],
[ 0., 0., 0., 12.]]])
shape: (3, 4, 4)
I couldn't find a solution trying to use the following identity matrix:
>>> np.tile(np.identity(4),(3,1)).reshape(3,4,4)
array([[[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]],
[[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]],
[[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]]])