LeanderK
(Leander Kurscheidt)
#1
I have a 2d-matrix and I want to split it using a checkerboard pattern. example:

```
1, 2, 3, 4
5, 6, 7, 8
9, 10, 11, 12
```

into

```
1, 3,
5, 7,
9, 11,
```

and

```
2, 4
6, 8
10, 12
```

this should be: `a = x[:, :, 0::2, :]`

and `b = x[:, :, 1::2, :]`

but now if I have `a`

and `b`

, how can I revert the transformation?

tom
(Thomas V)
#2
Depending on your style preferences, there are

```
x = torch.empty(a.size(0), a.size(1), 2*a.size(2), a.size(3), dtype=a.dtype, device=a.device)
x[:, :, 0::2, :] = a
x[:, :, 1::2, :] = b
```

and

```
x = torch.stack([a, b], 3).view(a.size(0), a.size(1), 2*a.size(2), a.size(3))
```

you could try.

The latter worked better with JIT a while ago when I looked at tracing maskrcnn-benchmark.

Best regards

Thomas

P.S.: To me it looks more like a striped than a checkerboard pattern.

LeanderK
(Leander Kurscheidt)
#3
thanks for the quick answer!

ah, yeah. You’re right, that’s not a checkboard-pattern. But I think I can adapt it to a real checkerboard-pattern.