I want to write a function with a tuple s (of length n) as an argument, which should return an array of shape s concatenated with (n,) (thus adding an extra dimension to the array), for which the data indexed by any tuple of length n (thus forgetting the last dimension) returns the tuple itself.
Here is an example of what it should do:
>>> a=f((2,3,4))
>>> a[1,1,1]
ndarray([1, 1, 1])
>>> a.shape
(2,3,4,3)
I managed to do it with the following code (if I am not wrong), but I am pretty sure it can be achieved in a more simple way:
a = np.transpose(
np.meshgrid(
*(np.arange(0, x) for x in s)),
axes = (2,1) + tuple(range(3, n+1)) + (0,))
(I hope I correctly copied my code since I had to simplify variables here.)