【发布时间】:2020-01-05 14:29:19
【问题描述】:
我在 numpy 中有一个网格点,我正在尝试对其进行插值。生成它们的代码如下:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.interpolate import Rbf
x = np.linspace(-1, 1, 100)[:, None] # inject trailing singleton for broadcasting
a, b = np.mgrid[0:1:0.1, 0:1:0.1]
#create dose distribution matrix
D = a.ravel() * x**2 + b.ravel() * x + 1
#perform SVD Decomposition
U, S, V = np.linalg.svd(D)
fig = plt.figure()
ax = plt.axes(projection="3d")
c0 = V[0]
#ax.scatter(a, b, c0)
#delete some points for testing interpolation
a_trng = a.ravel()
a_trng = np.append(a_trng[0:50], a_trng[70:100])
b_trng = b.ravel()
b_trng = np.append(b_trng[0:50], b_trng[70:100])
a_test = a_trng[50:70]
b_test = b_trng[50:70]
c0_trng = np.append(c0[0:50], c0[70:100])
c0_test = c0[50:70]
rbfi = Rbf(a_trng, b_trng, c0_trng)
ci = rbfi(a, b)
ax.scatter(a_trng, b_trng, c0_trng)
ax.scatter(a_test, b_test, c0_test)
我正在尝试删除一些点,test 点为插值创建 trng 点。然而,```test`` 点被移动了。如何对网格网格进行切片以免发生这种情况?
【问题讨论】:
标签: python arrays numpy multidimensional-array