Reputation: 793
I am new to python, I really appreciate it if you could help me.
I have a 2 column array i.e. d.T, and a 1 column array i.e. result and want to unite them in a 3 column array, I tried many times around but could not find the best way to do so, even I tried np.vstack but it doesn't work due to different dimensions.
import numpy as np
import math
n=3
m=3
T=4;
xmin=0; xmax=l=4
zmin=0; zmax=h=2
nx=5; nz=5
dx=(xmax-xmin)*1.0/(nx-1)
dz=(zmax-zmin)*1.0/(nz-1)
dt=0.00001
nt=1
k_z=n*2*math.pi/h
k_x=m*2*math.pi/l
w_theo=np.zeros((nz,nx),dtype='float64')
xx=[]
for i in range(0,nx):
xx.append(i*dx)
zz=[]
for k in range(0,nz):
zz.append(k*dz)
[x,z]=np.meshgrid(xx,zz)
for i in range(0,nz):
for k in range(0,nx):
t=0+nt*dt; omega=2*math.pi/T;
w_theo[i,k]=round(np.sin(k_z*i*dz*1.0)*np.sin(k_x*k*dx*1.0-omega*t),10)
print w_theo
np.savetxt('Theoretical_result.txt', np.array(w_theo), delimiter="\t")
d = np.array([x.flatten(), z.flatten()])
result=[]
for i in range(0,nz):
for k in range(0,nx):
result.append(w_theo[nz-1-i,k])
myarray=np.asarray(result)
print myarray.shape, d.T.shape`
# data=[]
# data=np.vstack((d.T,myarray))
# np.savetxt('datafile_id', data)
Upvotes: 0
Views: 66
Reputation: 78
Try
data = np.column_stack((d.T, myarray))
No need for data = []
Upvotes: 2