i was wondering if there is an easy way to do this:
a =
[[1,2],[3,4]]
b =
[[5,6],[7,8],[9,10]]
turning into this:
c =
[[[1,2], [1,2], [1,2]],
[[3,4], [3,4], [3,4]]]
d =
[[[5,6], [7,8], [9,10]],
[[5,6], [7,8], [9,10]]]
so i can do this:
c - d
i've already tried using np.meshgrid, but it was a really clunk:
indexes_b, indexes_a = np.meshgrid(
np.arange(a.shape[0]),
np.arange(b.shape[0])
)
c = a[indexes_a]
d = b[indexes_b]
c - d # works
Try this: