rearrange functionkeras.ops.rearrange(tensor, pattern, **axes_lengths)
Rearranges the axes of a Keras tensor according to a specified pattern, einops-style.
Arguments
Returns
Follows the logic of:
Example Usage:
```python
>>> import numpy as np
>>> from keras.ops import rearrange
>>> images = np.random.rand(32, 30, 40, 3) # BHWC format
>>> rearrange(images, 'b h w c -> b c h w').shape
TensorShape([32, 3, 30, 40])
>>> rearrange(images, 'b h w c -> (b h) w c').shape
TensorShape([960, 40, 3])
>>> rearrange(images, 'b h w c -> h (b w) c').shape
TensorShape([30, 1280, 3])
>>> rearrange(images, 'b h w c -> b (c h w)').shape
TensorShape([32, 3600])
>>> rearrange(images, 'b (h1 h) (w1 w) c -> (b h1 w1) h w c', h1=2, w1=2).shape
TensorShape([128, 15, 20, 3])
>>> rearrange(images, 'b (h h1) (w w1) c -> b h w (c h1 w1)', h1=2, w1=2).shape
TensorShape([32, 15, 20, 12])
```