I recently switched from numpy to ND4J but had a hard time understanding how broadcasting in ND4J works.
Say I have two ndarray, a of shape [3,2,4,5] and b of shape [2,4,5]. I would like to element-wise add them up and broadcast b to each a[i] for i = 0 to 2
. In numpy it can simply be done via a + b
, while in ND4J a.add(b)
throws an exception. I tried a.add(b.broadcast(3))
but still no luck.
What is the correct way of doing this in ND4J?