1We don't write:2 y = x.transpose(0, 2, 3, 1)3We write comprehensible code:4 y = rearrange(x, 'b c h w -> b h w c')5Also:6 rearrange(ims, "b h w c -> h (b w) c").shape7 rearrange(ims, "(b1 b2) h w c -> b1 b2 h w c ", b1=2).shape8 reduce(ims, "b h w c -> h w c", "mean") # Average overbatch9 reduce(ims, "b h w c -> h w", "min")and einx
1z = einx.id("a (b c) -> (b a) c", x, b=2) # Permute and (un)flatten axes2z = einx.id("b (q + k) -> b q, b k", x, q=2) # Split3z = einx.id("b c, -> b (c + 1)", x, 42) # Append number to each channel4z = einx.sum("a [b]", x) # Sum-reduction along second axis5z = einx.flip("... (g [c])", x, c=2) # Flip pairs of values along the last axis6z = einx.mean("b [...] c", x) # Spatial mean-pooling7z = einx.multiply("a..., b... -> (a b)...", x, y) # Kronecker product8z = einx.sum("b (s [ds])... c", x, ds=(2, 2)) # Sum-pooling with 2x2 kernel9z = einx.add("a, b -> a b", x, y) # Outer sum10z = einx.dot("a [b], [b] c -> a c", x, y) # Matrix multiplication11z = einx.get_at("b [h w] c, b i [2] -> b i c", x, y) # Gather values at coordinates