I have a numpy array with dimensions 12 x 12 x 4. Now I'm trying to add an extra layer to this cube resulting in a 12 x 13 x 4 array. This 13th layer should contain the corresponding indices from the first axis, so for example addressing [7, 13, :] results in [7, 7, 7, 7].
Hard to explain but maybe someone has some advice on how to achieve this with numpy?
EDIT: I've found a solution, though it seems a little overcomplicated:
# Generate extra layer
layer = np.repeat(np.arange(0, 12)[:, np.newaxis], data.shape[2], axis=1)
# Get dimensions right...
layer = np.expand_dims(layer, axis=1)
# ... and finally append to data
result = np.append(data, layer, axis=1)
Still open for better suggestions.
concatenate. But be careful about dimensions.