在创建了4组均匀间隔的数字(通过linspace)并加载了一组坐标和到达时间(与方程有关,有20个不同的坐标集)之后,我创建了四个循环以获取rms值每组变量(应该有24255个不同的集合),但是到目前为止,我得到的都是20 rms值。
我将如何在网格中获取所有必要的值,它还显示了相应的x,y,z,t0值?
这是我使用的代码:
import numpy as np
#opening files
s_Coord = np.genfromtxt(fname = 's_Coord_Pset3.txt')
t_ob = np.genfromtxt(fname ='t_ob_Pset3File.txt')
#creating parameters
nt0 = 5
t0_vec = np.linspace(0,4,nt0)
nx = 21
x_vec = np.linspace(-20,20,nx)
ny = 21
y_vec = np.linspace(-20,20,ny)
nz = 11
z_vec = np.linspace(0,20,nz)
v = 6 #km
#calculating ti_p and rms
for x in x_vec:
for y in y_vec:
for z in z_vec:
for t0 in t0_vec:
rms_mat = np.zeros((nx,ny,nz,nt0))
#the rms_mat zeros matrix is possibly for creating the grid to fill?
g_range = np.arange(0,20,1) #for 20 stations from the file
x1 = [s_Coord[g:g+1,0] for g in g_range]
y1 = [s_Coord[g:g+1,1] for g in g_range]
z1 = [s_Coord[g:g+1,2] for g in g_range]
t0 = [t_ob[g:g+1] for g in g_range]
ti_p = t0+(((x1-x)**2+(y1-y)**2+(z1-z)**2)**0.5)/v
rms = ((((t0-ti_p)**2)/(nx*ny*nz*nt0))**0.5)
对此的任何帮助将不胜感激
您正在覆盖rms数组。您要预分配均方根并将本地计算的数组写入均方根切片,或者要追加。