我明白interp1d
期望一个值的数组进行插值,但是当传入一个浮点数时,其行为很奇怪,需要问一下具体发生了什么以及返回了什么。
import numpy as np
from scipy.interpolate import interp1d
x = np.array([1,2,3,4])
y = np.array([5,7,9,15])
f = interp1d(x,y, kind='cubic')
a = f(2.5)
print(repr(a))
print("type is {}".format(type(a)))
print("shape is {}".format(a.shape))
print("ndim is {}".format(a.ndim))
print(a)
输出:
array(7.749999999999992)
type is <class 'numpy.ndarray'>
shape is ()
ndim is 0
7.749999999999992
编辑:为了澄清,我甚至不希望numpy有一个无维度、无形状的数组,更不用说scipy函数会返回这样一个数组了。
print("Numpy version is {}".format(np.__version__))
print("Scipy version is {}".format(scipy.__version__))
Numpy version is 1.10.4
Scipy version is 0.17.0
float
,并且你想知道这是否是一个错误。 - Fabian Rost