I wrote the following code:
I'm in trouble because I don't know the reason.Could someone explain it to me?dy[0][0:1]
failed to retrieve the first number in the list, so dy_sum
can be shaped once and dy_sum[0:1]
can retrieve the first number in the list, but for some reason dx[0][0:1]
must be .
import numpy as np
D,N = 8,7
x = np.random.randn(1,D)
y=np.repeat(x,N,axis=0)
dy=np.random.randn(N,D)
dx=np.sum (dy,axis=0, keepdims=True)
dy_sum=np.sum(dy,axis=0)
print(dy_sum[0:1])
print(dx[0][0:1])
keepdims=True
, so the dimensions of dx
(ndim
) are 2
.
If keepdims=False
or keepdims
is not specified, dx[0]
can retrieve the first value.
dx[0]
was taken out when ndim set 2
→False to 1
.
This post is a comment from @ladleDear @yokomizo-groove,I posted it as a community wiki based on the comments in .
© 2024 OneMinuteCode. All rights reserved.