简体   繁体   English

将各种2D矩阵保存到python中的3D矩阵中

[英]saving various 2D matrices into a 3D matrix in python

I am trying to save various 2D matrices from python into a 3D matrix, but I'm receiving an error, here are the matrices: 我试图将各种2D矩阵从python保存到3D矩阵中,但我收到一个错误,这里是矩阵:

rho=np.zeros((Nx,Nt))
p=np.zeros((Nx,Nt))
u=np.zeros((Nx,Nt))
U=np.zeros((Nx,Nt,3))
F=np.zeros((Nx,Nt,3))

I'm trying to save combinations of the first three into the last two like this: 我试图将前三个的组合保存到最后两个中,如下所示:

F[:][:][0]=u*rho
F[:][:][1]=p*u**2+p
F[:][:][2]=u(e + p)

know that e is another NX by Nt matrix in another part of the code, it seems I'm not assigning this properly as I get an error saying I can't save a 1000*1000 matrix into a 1000*3 matrix, which is understandable, but of course my idea is to save the 1000*1000 matrix into the first "element" of my 3d matrix F and other combinations into my U matrix and so on, can anyone tell me how to do this, saving the 2d matrices into indexes of 3d matrices, I also tried with U[0][:][:]=rho 知道e是另一部分代码中的另一个NX by Nt矩阵,似乎我没有正确分配这个,因为我得到一个错误,说我无法将1000 * 1000矩阵保存到1000 * 3矩阵中,这是可以理解,但当然我的想法是将1000 * 1000矩阵保存到我的3d矩阵F的第一个“元素”中,将其他组合保存到我的U矩阵等等,任何人都可以告诉我如何做到这一点,保存2d矩阵进入3d矩阵的索引,我也试过U[0][:][:]=rho

正如Divakar指出的那样,我没有正确使用索引,使用F[:,:,0]=u*rho等,纠正了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM