Reputation: 15
I've got a 3D and a 1D numpy array- A sized (3750, 17, 1000) and B sized (3750). I want to replace the values in the 1st dimension of A with the values from array B, so that the resulting array C is still sized (3750, 17, 1000), but the values in the first dimension are different.
>>> A.shape
(3750, 17, 1000)
>>> B.shape (3750,)
>>> C.shape(3750, 17, 1000)
I've tried:
>>> C = np.concatenate((A, np.broadcast_to(np.array(B)[:, None, None],A.shape)), axis = 0)
But the output is:
>>> C.shape (7500, 17, 1000)
So basically if
A =
1 [x, y ... 1000]
[x, y ... 1000]
...17
2 [x, y ... 1000]
[x, y ... 1000]
...17
3 [x, y ... 1000]
[x, y ... 1000]
...17
.
.
.
3750
and B =
22
43
11
.
.
n=3750
Then C should look like
22 [x, y ... 1000]
[x, y ... 1000]
...17
43 [x, y ... 1000]
[x, y ... 1000]
...17
11 [x, y ... 1000]
[x, y ... 1000]
...17
.
.
.
n=3750
Upvotes: 1
Views: 2396