gpt4 book ai didi

python - PYTHON上使用griddata的未知插值方法数组

转载 作者:太空宇宙 更新时间:2023-11-03 17:11:13 26 4
gpt4 key购买 nike

我已经花了两天时间寻找答案,但我一直遇到同样的错误,我不明白为什么。无论我做什么,我总是收到错误“ValueError:一维数据的未知插值方法数组”

我正在尝试使用 griddata 将值插入到更精细的网格中

这是我的代码

import numpy as np

lon_ww3=array([[-10. , -10. , -10. , -10. , -10. , -10. , -10. , -10. , -10. ],
[ -9.5, -9.5, -9.5, -9.5, -9.5, -9.5, -9.5, -9.5, -9.5],
[ -9. , -9. , -9. , -9. , -9. , -9. , -9. , -9. , -9. ],
[ -8.5, -8.5, -8.5, -8.5, -8.5, -8.5, -8.5, -8.5, -8.5]])

lat_ww3=array([[ 38. , 38.5, 39. , 39.5, 40. , 40.5, 41. , 41.5, 42. ],
[ 38. , 38.5, 39. , 39.5, 40. , 40.5, 41. , 41.5, 42. ],
[ 38. , 38.5, 39. , 39.5, 40. , 40.5, 41. , 41.5, 42. ],
[ 38. , 38.5, 39. , 39.5, 40. , 40.5, 41. , 41.5, 42. ]])

Z=np.random.random_sample((4,9))*3

#Create finer mesh grid

lon_pn=[-10,-9]
lat_pn=[38,42]

lon_points=np.arange(lon_pn[0],lon_pn[1]+(300./3600),300./3600)[:-1]
lat_points=np.arange(lat_pn[0],lat_pn[1]+(300./3600),300./3600)[:-1]

LON_grid,LAT_grid=np.meshgrid(lon_points,lat_points)

from scipy.interpolate import griddata

Z_interp=griddata(lon_ww3.ravel(),lat_ww3.ravel(), Z.ravel(),LON_grid,LAT_grid)

我也尝试过这个,显然没有成功:

Z_interp=griddata(lon_ww3.ravel(),lat_ww3.ravel(), Z.ravel(),lon_points,lat_points)

几乎我能想到的所有可能的变化......每次我都会遇到相同的错误:

“ValueError:“第 n”维数据的未知插值方法数组 [LON_grid]”

任何人都可以尝试重现代码并帮助我找出发生了什么吗?

提前致谢

保罗

最佳答案

您对 griddata 的使用情况是错误的。

将这些行添加到您的代码示例中。

xi = np.c_[lon_ww3.ravel(),lat_ww3.ravel()]
xx = np.c_[LON_grid.ravel(),LAT_grid.ravel()]

Z_interp=griddata(xi,Z.ravel(),xx)

xi 是原始网格点的 n,D 向量。xx 是插值点的 N,D 向量。

np.c_是坐标各方向的列栈。

关于python - PYTHON上使用griddata的未知插值方法数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34065546/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com