Учитывая некоторые данные
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
x = [0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.46,0.46,0.46,0.46,0.46,0.46,0.46,0.46,0.46,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,]
y = [0.01,0.01,0.01,0.255,0.255,0.255,0.5,0.5,0.5,0.01,0.01,0.01,0.255,0.255,0.255,0.5,0.5,0.5,0.01,0.01,0.01,0.255,0.255,0.255,0.5,0.5,0.5,]
z = [0.,0.1,0.2,0.,0.1,0.2,0.,0.1,0.2,0.,0.1,0.2,0.,0.1,0.2,0.,0.1,0.2,0.,0.1,0.2,0.,0.1,0.2,0.,0.1,0.2]
v = [0.,0.,1.,0.,1.,1.,0.,1.,1.,0.,0.,0.,0.,0.5,1.,0.,1.,1.,0.,0.,0.,0.,0.,0.,0.,0.5,1.,]
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
c = ax.scatter(x, y, z, c = v, s = 100, cmap = plt.cm.bwr, edgecolor = "black", alpha = 0.2)
ax.scatter(0.51, 0.32, 0.12, s = 100, c = "black", edgecolor = "black")
plt.show()
Я хочу получить функцию f(x,y,z)
, чтобы выяснить, какое значение v
должно быть в любой произвольной позиции.Просто, правда?Тогда почему я не могу из-за любви к Сципи понять, как это сделать?
Приведенные мной примеры определяют x, y, z, определяют красивую сетку некоторых сортов и оценивают, чтобы получить v
в правильной форме и порядке.Вот где мои попытки рушатся.Что если все данные изначально отформатированы как 1D?
Я думал, что смогу сделать
V = zeros((len(x),len(y),len(z)))
for i in range(len(x)):
V[i, None, None] = v[i]
for j in range(len(y)):
V[None, j, None] = v[j]
for k in range(len(z)):
V[None, None, k] = v[k]
fn = RegularGridInterpolator((x,y,z), V)
Но это возвращает ValueError: The points in dimension 0 must be strictly ascending