简体   繁体   中英

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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