It looks like _y
is just a copy of y
that has been reshaped by interp1d._reshape_yi()
. It should therefore be safe to just update it using:
self.itpr._y = self.itpr._reshape_yi(self.itpr.y)
In fact, as far as I can tell it's only _y
that gets used internally by the interpolator, so I think you could get away without actually updating y
at all.
A much more elegant solution would be to make _y
a property of the interpolator that returns a suitably reshaped copy of y
. It's possible to achieve this by monkey-patching your specific instance of interp1d
after it has been created (see Alex Martelli's answer here for more explanation):
x = np.arange(100)
y = np.random.randn(100)
itpr = interp1d(x,y)
# method to get self._y from self.y
def get_y(self):
return self._reshape_yi(self.y)
meth = property(get_y,doc='reshaped version of self.y')
# make this a method of this interp1d instance only
basecls = type(itpr)
cls = type(basecls.__name__, (basecls,), {})
setattr(cls, '_y', meth)
itpr.__class__ = cls
# itpr._y is just a reshaped version of itpr.y
print itpr.y.shape,itpr._y.shape
>>> (100,) (100, 1)
Now itpr._y
gets updated when you update itpr.y
itpr.x = np.arange(110)
itpr.y = np.random.randn(110)
print itpr._y.shape
>>> (110,) (110, 1)
This is all quite fiddly and not very Pythonic - it's much easier to fix the scipy source code (scipy/interpolate/interpolate.py). All you'd need to do is remove the last line from interp1d.__init__()
where it sets:
self._y = y
and add these lines:
@property
def _y(self):
return self._reshape_yi(self.y)