I'm trying to broadcast the contents of one array into another array like this:
A = np.array([[1, 3], [2, 4]])
A_broadcast = np.array([[1, 0, 3, 0], [0, 2, 0, 4], [1, 2, 3, 4]])
My current approach is by initializing A_broadcast
with np.zeros((3, 4))
and slicing the contents of A
into A_broadcast
one line at a time like this:
A_broadcast[::2][0] = A[0]
A_broadcast[1::2][1] = A[1]
A_broadcast[::2][2] = A[0]
A_broadcast[1::2][2] = A[1]
But I get this error: ValueError: could not broadcast input array from shape (2,) into shape (4,)
This approach works in Matlab so I thought something similar would work here. Is there a way this approach can work? If not, what could I do to get a similar effect?