1 回答
TA贡献1794条经验 获得超8个赞
你可以使用这个:
编辑:由于@hpaulj 的评论,在下一行评论,添加了下一行。
# new_A = np.stack((x,y,np.ones_like(z)), axis=1).swapaxes(1,2)
new_A = np.stack((x,y,np.ones_like(z)), axis=2)
测试一下:
THOUSAND = 6
x = np.random.randint(1,5,size=(THOUSAND,5))
y = np.random.randint(1,5,size=(THOUSAND,5))
z = np.random.randint(1,5,size=(THOUSAND,5))
print (x)
print (y)
print (z)
new_A = np.stack((x,y,np.ones_like(z)), axis=1).swapaxes(1,2)
print (new_A)
输出:
[[1 2 2 1 1] # print(x)
[4 4 4 4 4]
[1 2 1 3 3]
[2 3 1 4 4]
[1 1 4 1 4]
[4 1 3 3 2]]
[[2 2 3 4 4] # print(y)
[1 1 4 2 1]
[3 3 1 1 2]
[1 1 2 1 3]
[3 2 1 4 3]
[4 4 1 3 2]]
[[3 4 3 2 2] # print(z)
[4 2 4 3 3]
[3 3 4 1 4]
[4 3 3 3 1]
[4 1 1 3 3]
[4 1 4 3 3]]
# new_A output
[[[1 2 1] # print(new_A)
[2 2 1]
[2 3 1]
[1 4 1]
[1 4 1]]
[[4 1 1]
[4 1 1]
[4 4 1]
[4 2 1]
[4 1 1]]
[[1 3 1]
[2 3 1]
[1 1 1]
[3 1 1]
[3 2 1]]
[[2 1 1]
[3 1 1]
[1 2 1]
[4 1 1]
[4 3 1]]
[[1 3 1]
[1 2 1]
[4 1 1]
[1 4 1]
[4 3 1]]
[[4 4 1]
[1 4 1]
[3 1 1]
[3 3 1]
[2 2 1]]]
添加回答
举报