热线电话:13121318867

登录
2019-03-07 阅读量: 706
替换给定轴的值

考虑以下几点:

一个numpy超立方体例如 x = np.random.rand(8, 8, 8, 8)

尺寸指数,例如 dim = 1

替换阵列,例如 y = np.random.rand(8)

如何替换给定尺寸的所有值?

也就是说,我能做得比:

if dim == 0:

x[0,:,:,:] = y

elif dim == 1:

x[:,0,:,:] = y

elif dim == 2:

x[:,:,0,:] = y

elif dim == 3:

x[:,:,:,0] = y

else:

throw

解决办法:您可以将dim'th轴移动到前面:

np.moveaxis(x, dim, 0)[0] = y

10.7653
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子