填充numpy的阵列的列与另一阵列 [英] Fill a column of a numpy array with another array

查看:209
本文介绍了填充numpy的阵列的列与另一阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

x = np.zeros((96,11,11,2,10),dtype=np.float64)
y = np.array([0,10,20,30,40,50,60,70,80,90,100],dtype=np.float64)
x[:,:,:,0,0] = y
print x[0,:,:,0,0]

我得到:

[[   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]
 [   0.   10.   20.   30.   40.   50.   60.   70.   80.   90.  100.]]

但我想要的输出(在第一维的我)成为这个转。即填列而不是行

but I want the output (for any i in first dimension) to be the transpose of this. ie fill columns instead of rows

有什么建议?

推荐答案

您需要修改从一维到二维(与一列):

You need to change y from 1D to 2D (with one column):

x[:,:,:,0,0] = y[:, np.newaxis]

x[:,:,:,0,0] = y.reshape(11,1)

这篇关于填充numpy的阵列的列与另一阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆