pythoninterp error_Python numpy.interp方法代码示例
本文整理匯總了Python中numpy.interp方法的典型用法代碼示例。如果您正苦于以下問題:Python numpy.interp方法的具體用法?Python numpy.interp怎么用?Python numpy.interp使用的例子?那么恭喜您, 這里精選的方法代碼示例或許可以為您提供幫助。您也可以進(jìn)一步了解該方法所在模塊numpy的用法示例。
在下文中一共展示了numpy.interp方法的29個(gè)代碼示例,這些例子默認(rèn)根據(jù)受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點(diǎn)贊,您的評(píng)價(jià)將有助于我們的系統(tǒng)推薦出更棒的Python代碼示例。
示例1: __init__
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def __init__(self,alpha_max,Tg,xi):
gamma=0.9+(0.05-xi)/(0.3+6*xi)
eta1=0.02+(0.05-xi)/(4+32*xi)
eta1=eta1 if eta1>0 else 0
eta2=1+(0.05-xi)/(0.08+1.6*xi)
eta2=eta2 if eta2>0.55 else 0.55
T=np.linspace(0,6,601)
alpha=[]
for t in T:
if t<0.1:
alpha.append(np.interp(t,[0,0.1],[0.45*alpha_max,eta2*alpha_max]))
elif t
alpha.append(eta2*alpha_max)
elif t<5*Tg:
alpha.append((Tg/t)**gamma*eta2*alpha_max)
else:
alpha.append((eta2*0.2**gamma-eta1*(t-5*Tg))*alpha_max)
self.__spectrum={'T':T,'alpha':alpha}
開發(fā)者ID:zhuoju36,項(xiàng)目名稱:StructEngPy,代碼行數(shù):20,
示例2: spectrum_analysis
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def spectrum_analysis(model,n,spec):
"""
sepctrum analysis
params:
n: number of modes to use\n
spec: a list of tuples (period,acceleration response)
"""
freq,mode=eigen_mode(model,n)
M_=np.dot(mode.T,model.M)
M_=np.dot(M_,mode)
K_=np.dot(mode.T,model.K)
K_=np.dot(K_,mode)
C_=np.dot(mode.T,model.C)
C_=np.dot(C_,mode)
d_=[]
for (m_,k_,c_) in zip(M_.diag(),K_.diag(),C_.diag()):
sdof=SDOFSystem(m_,k_)
T=sdof.omega_d()
d_.append(np.interp(T,spec[0],spec[1]*m_))
d=np.dot(d_,mode)
#CQC
return d
開發(fā)者ID:zhuoju36,項(xiàng)目名稱:StructEngPy,代碼行數(shù):25,
示例3: nan_helper
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def nan_helper(y):
"""Helper to handle indices and logical indices of NaNs.
Input:
- y, 1d numpy array with possible NaNs
Output:
- nans, logical indices of NaNs
- index, a function, with signature indices= index(logical_indices),
to convert logical indices of NaNs to 'equivalent' indices
Example:
>>> # linear interpolation of NaNs
>>> nans, x= nan_helper(y)
>>> y[nans]= np.interp(x(nans), x(~nans), y[~nans])
"""
return np.isnan(y), lambda z: z.nonzero()[0]
開發(fā)者ID:BruceBinBoxing,項(xiàng)目名稱:Deep_Learning_Weather_Forecasting,代碼行數(shù):18,
示例4: test_control_curve_interpolated_json
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_control_curve_interpolated_json(use_parameters):
# this is a little hack-y, as the parameters don't provide access to their
# data once they've been initalised
if use_parameters:
model = load_model("reservoir_with_cc_param_values.json")
else:
model = load_model("reservoir_with_cc.json")
reservoir1 = model.nodes["reservoir1"]
model.setup()
path = os.path.join(os.path.dirname(__file__), "models", "control_curve.csv")
control_curve = pd.read_csv(path)["Control Curve"].values
values = [-8, -6, -4]
@assert_rec(model, reservoir1.cost)
def expected_cost(timestep, si):
# calculate expected cost manually and compare to parameter output
volume_factor = reservoir1._current_pc[si.global_id]
cc = control_curve[timestep.index]
return np.interp(volume_factor, [0.0, cc, 1.0], values[::-1])
model.run()
開發(fā)者ID:pywr,項(xiàng)目名稱:pywr,代碼行數(shù):22,
示例5: test_circular_control_curve_interpolated_json
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_circular_control_curve_interpolated_json():
# this is a little hack-y, as the parameters don't provide access to their
# data once they've been initalised
model = load_model("reservoir_with_circular_cc.json")
reservoir1 = model.nodes["reservoir1"]
model.setup()
path = os.path.join(os.path.dirname(__file__), "models", "control_curve.csv")
control_curve = pd.read_csv(path)["Control Curve"].values
values = [-8, -6, -4]
@assert_rec(model, reservoir1.cost)
def expected_cost(timestep, si):
# calculate expected cost manually and compare to parameter output
volume_factor = reservoir1._current_pc[si.global_id]
cc = control_curve[timestep.index]
return np.interp(volume_factor, [0.0, cc, 1.0], values[::-1])
model.run()
開發(fā)者ID:pywr,項(xiàng)目名稱:pywr,代碼行數(shù):19,
示例6: colormap
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def colormap(x, m=None, M=None, center=0, colors=None):
'''color a grayscale array (currently red/blue by sign)'''
if center is None:
center = 0
if colors is None:
colors = np.array(((0, 0.7, 1),
(0, 0, 0),
(1, 0, 0)),
dtype=float)
if x.shape[-1] == 1:
x = x[..., 0]
x = scale_values(x, min=m, max=M, center=center)
y = np.empty(x.shape + (3,))
for c in xrange(3):
y[..., c] = np.interp(x, (0, 0.5, 1), colors[:, c])
return y
開發(fā)者ID:hjimce,項(xiàng)目名稱:Depth-Map-Prediction,代碼行數(shù):18,
示例7: cor_2_1d
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def cor_2_1d(cor, H, W):
bon_ceil_x, bon_ceil_y = [], []
bon_floor_x, bon_floor_y = [], []
n_cor = len(cor)
for i in range(n_cor // 2):
xys = panostretch.pano_connect_points(cor[i*2],
cor[(i*2+2) % n_cor],
z=-50, w=W, h=H)
bon_ceil_x.extend(xys[:, 0])
bon_ceil_y.extend(xys[:, 1])
for i in range(n_cor // 2):
xys = panostretch.pano_connect_points(cor[i*2+1],
cor[(i*2+3) % n_cor],
z=50, w=W, h=H)
bon_floor_x.extend(xys[:, 0])
bon_floor_y.extend(xys[:, 1])
bon_ceil_x, bon_ceil_y = sort_xy_filter_unique(bon_ceil_x, bon_ceil_y, y_small_first=True)
bon_floor_x, bon_floor_y = sort_xy_filter_unique(bon_floor_x, bon_floor_y, y_small_first=False)
bon = np.zeros((2, W))
bon[0] = np.interp(np.arange(W), bon_ceil_x, bon_ceil_y, period=W)
bon[1] = np.interp(np.arange(W), bon_floor_x, bon_floor_y, period=W)
bon = ((bon + 0.5) / H - 0.5) * np.pi
return bon
開發(fā)者ID:sunset1995,項(xiàng)目名稱:HorizonNet,代碼行數(shù):25,
示例8: test_zero_dimensional_interpolation_point
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_zero_dimensional_interpolation_point(self):
x = np.linspace(0, 1, 5)
y = np.linspace(0, 1, 5)
x0 = np.array(.3)
assert_almost_equal(np.interp(x0, x, y), x0)
xp = np.array([0, 2, 4])
fp = np.array([1, -1, 1])
actual = np.interp(np.array(1), xp, fp)
assert_equal(actual, 0)
assert_(isinstance(actual, np.float64))
actual = np.interp(np.array(4.5), xp, fp, period=4)
assert_equal(actual, 0.5)
assert_(isinstance(actual, np.float64))
開發(fā)者ID:Frank-qlu,項(xiàng)目名稱:recruit,代碼行數(shù):18,
示例9: test_interpolate_index_values
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_interpolate_index_values(self):
s = Series(np.nan, index=np.sort(np.random.rand(30)))
s[::3] = np.random.randn(10)
vals = s.index.values.astype(float)
result = s.interpolate(method='index')
expected = s.copy()
bad = isna(expected.values)
good = ~bad
expected = Series(np.interp(vals[bad], vals[good],
s.values[good]),
index=s.index[bad])
assert_series_equal(result[bad], expected)
# 'values' is synonymous with 'index' for the method kwarg
other_result = s.interpolate(method='values')
assert_series_equal(other_result, result)
assert_series_equal(other_result[bad], expected)
開發(fā)者ID:Frank-qlu,項(xiàng)目名稱:recruit,代碼行數(shù):24,
示例10: sample_posterior
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def sample_posterior(self, x, n=1):
r"""
Generates :code:`n` samples from the estimated posterior
distribution for the input vector :code:`x`. The sampling
is performed by the inverse CDF method using the estimated
CDF obtained from the :code:`cdf` member function.
Arguments:
x(np.array): Array of shape `(n, m)` containing `n` inputs for which
to predict the conditional quantiles.
n(int): The number of samples to generate.
Returns:
Tuple (xs, fs) containing the :math: `x`-values in `xs` and corresponding
values of the posterior CDF :math: `F(x)` in `fs`.
"""
y_pred, qs = self.cdf(x)
p = np.random.rand(n)
y = np.interp(p, qs, y_pred)
return y
開發(fā)者ID:atmtools,項(xiàng)目名稱:typhon,代碼行數(shù):25,
示例11: interp_batch
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def interp_batch(total_batch_x):
interp_batch_x = total_batch_x.copy()
N_batch = total_batch_x.shape[0]
for n in range(N_batch):
temp_idx = np.where(total_batch_x[n,0,:,1]==1)[0]
t1 = int(temp_idx[-1])
temp_idx = np.where(total_batch_x[n,0,:,2]==1)[0]
t2 = int(temp_idx[0])
if t2-t1<=1:
continue
interp_t = np.array(range(t1+1,t2))
for k in range(total_batch_x.shape[1]):
#temp_std = np.std(total_batch_x[n,k,total_batch_x[n,k,:,0]!=0,0])
temp_std1 = np.std(total_batch_x[n,k,total_batch_x[n,0,:,1]!=0,0])
temp_std2 = np.std(total_batch_x[n,k,total_batch_x[n,0,:,2]!=0,0])
x_p = [t1,t2]
f_p = [total_batch_x[n,k,t1,0],total_batch_x[n,k,t2,0]]
#interp_batch_x[n,k,t1+1:t2,0] = np.interp(interp_t,x_p,f_p)#+np.random.normal(0, temp_std, t2-t1-1)
interp_batch_x[n,k,t1+1:t2,0] = np.interp(interp_t,x_p,f_p)+np.random.normal(0, (temp_std1+temp_std2)*0.5, t2-t1-1)
return interp_batch_x
開發(fā)者ID:GaoangW,項(xiàng)目名稱:TNT,代碼行數(shù):24,
示例12: interp_batch
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def interp_batch(total_batch_x):
interp_batch_x = total_batch_x.copy()
N_batch = total_batch_x.shape[0]
for n in range(N_batch):
temp_idx = np.where(total_batch_x[n,0,:,1]==1)[0]
t1 = int(temp_idx[-1])
temp_idx = np.where(total_batch_x[n,0,:,2]==1)[0]
t2 = int(temp_idx[0])
if t2-t1<=1:
continue
interp_t = np.array(range(t1+1,t2))
for k in range(total_batch_x.shape[1]):
#temp_std = np.std(total_batch_x[n,k,total_batch_x[n,k,:,0]!=0,0])
temp_std1 = np.std(total_batch_x[n,k,total_batch_x[n,0,:,1]!=0,0])
temp_std2 = np.std(total_batch_x[n,k,total_batch_x[n,0,:,2]!=0,0])
x_p = [t1,t2]
f_p = [total_batch_x[n,k,t1,0],total_batch_x[n,k,t2,0]]
#*************************************
#interp_batch_x[n,k,t1+1:t2,0] = np.interp(interp_t,x_p,f_p)+np.random.normal(0, temp_std, t2-t1-1)
#*************************************
interp_batch_x[n,k,t1+1:t2,0] = np.interp(interp_t,x_p,f_p)+np.random.normal(0, (temp_std1+temp_std2)*0.5, t2-t1-1)
return interp_batch_x
開發(fā)者ID:GaoangW,項(xiàng)目名稱:TNT,代碼行數(shù):24,
示例13: test_complex_interp
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_complex_interp(self):
# test complex interpolation
x = np.linspace(0, 1, 5)
y = np.linspace(0, 1, 5) + (1 + np.linspace(0, 1, 5))*1.0j
x0 = 0.3
y0 = x0 + (1+x0)*1.0j
assert_almost_equal(np.interp(x0, x, y), y0)
# test complex left and right
x0 = -1
left = 2 + 3.0j
assert_almost_equal(np.interp(x0, x, y, left=left), left)
x0 = 2.0
right = 2 + 3.0j
assert_almost_equal(np.interp(x0, x, y, right=right), right)
# test complex periodic
x = [-180, -170, -185, 185, -10, -5, 0, 365]
xp = [190, -190, 350, -350]
fp = [5+1.0j, 10+2j, 3+3j, 4+4j]
y = [7.5+1.5j, 5.+1.0j, 8.75+1.75j, 6.25+1.25j, 3.+3j, 3.25+3.25j,
3.5+3.5j, 3.75+3.75j]
assert_almost_equal(np.interp(x, xp, fp, period=360), y)
開發(fā)者ID:ryfeus,項(xiàng)目名稱:lambda-packs,代碼行數(shù):23,
示例14: linear_interpolation
?點(diǎn)贊 6
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def linear_interpolation(x, xp, fp, **kwargs):
"""Multi-dimensional linear interpolation.
Returns the multi-dimensional piecewise linear interpolant to a function with
given discrete data points (xp, fp), evaluated at x.
Note that *N and *M indicate zero or more dimensions.
Args:
x: An array of shape [*N], the x-coordinates of the interpolated values.
xp: An np.array of shape [D], the x-coordinates of the data points, must be
increasing.
fp: An np.array of shape [D, *M], the y-coordinates of the data points.
**kwargs: Keywords for np.interp.
Returns:
An array of shape [*N, *M], the interpolated values.
"""
yp = fp.reshape([fp.shape[0], -1]).transpose()
y = np.stack([np.interp(x, xp, zp, **kwargs) for zp in yp]).transpose()
return y.reshape(x.shape[:1] + fp.shape[1:]).astype(np.float32)
開發(fā)者ID:tensorflow,項(xiàng)目名稱:tensor2tensor,代碼行數(shù):23,
示例15: _convert_to_torque_from_pwm
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def _convert_to_torque_from_pwm(self, pwm, true_motor_velocity):
"""Convert the pwm signal to torque.
Args:
pwm: The pulse width modulation.
true_motor_velocity: The true motor velocity at the current moment. It is
used to compute the back EMF voltage and the viscous damping.
Returns:
actual_torque: The torque that needs to be applied to the motor.
observed_torque: The torque observed by the sensor.
"""
observed_torque = np.clip(
self._torque_constant *
(np.asarray(pwm) * self._voltage / self._resistance),
-OBSERVED_TORQUE_LIMIT, OBSERVED_TORQUE_LIMIT)
# Net voltage is clipped at 50V by diodes on the motor controller.
voltage_net = np.clip(
np.asarray(pwm) * self._voltage -
(self._torque_constant + self._viscous_damping) *
np.asarray(true_motor_velocity), -VOLTAGE_CLIPPING, VOLTAGE_CLIPPING)
current = voltage_net / self._resistance
current_sign = np.sign(current)
current_magnitude = np.absolute(current)
# Saturate torque based on empirical current relation.
actual_torque = np.interp(current_magnitude, self._current_table,
self._torque_table)
actual_torque = np.multiply(current_sign, actual_torque)
actual_torque = np.multiply(self._strength_ratios, actual_torque)
return actual_torque, observed_torque
開發(fā)者ID:utra-robosoccer,項(xiàng)目名稱:soccer-matlab,代碼行數(shù):32,
示例16: _convert_to_torque_from_pwm
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def _convert_to_torque_from_pwm(self, pwm, current_motor_velocity):
"""Convert the pwm signal to torque.
Args:
pwm: The pulse width modulation.
current_motor_velocity: The motor velocity at the current time step.
Returns:
actual_torque: The torque that needs to be applied to the motor.
observed_torque: The torque observed by the sensor.
"""
observed_torque = np.clip(
self._torque_constant * (pwm * self._voltage / self._resistance),
-OBSERVED_TORQUE_LIMIT, OBSERVED_TORQUE_LIMIT)
# Net voltage is clipped at 50V by diodes on the motor controller.
voltage_net = np.clip(pwm * self._voltage -
(self._torque_constant + self._viscous_damping)
* current_motor_velocity,
-VOLTAGE_CLIPPING, VOLTAGE_CLIPPING)
current = voltage_net / self._resistance
current_sign = np.sign(current)
current_magnitude = np.absolute(current)
# Saturate torque based on empirical current relation.
actual_torque = np.interp(current_magnitude, self._current_table,
self._torque_table)
actual_torque = np.multiply(current_sign, actual_torque)
return actual_torque, observed_torque
開發(fā)者ID:utra-robosoccer,項(xiàng)目名稱:soccer-matlab,代碼行數(shù):30,
示例17: test_control_curve_interpolated
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_control_curve_interpolated(model, use_parameters):
m = model
m.timestepper.delta = 200
s = m.nodes['Storage']
o = m.nodes['Output']
s.connect(o)
cc = ConstantParameter(model, 0.8)
values = [20.0, 5.0, 0.0]
if use_parameters:
# Create the parameter using parameters for the values
parameters = [ConstantParameter(model, v) for v in values]
s.cost = p = ControlCurveInterpolatedParameter(model, s, cc, parameters=parameters)
else:
# Create the parameter using a list of values
s.cost = p = ControlCurveInterpolatedParameter(model, s, cc, values)
@assert_rec(model, p)
def expected_func(timestep, scenario_index):
v = s.initial_volume
c = cc.value(timestep, scenario_index)
if c == 1.0 and v == 100.0:
expected = values[1]
elif c == 0.0 and v == 0.0:
expected = values[1]
else:
expected = np.interp(v/100.0, [0.0, c, 1.0], values[::-1])
return expected
for control_curve in (0.0, 0.8, 1.0):
cc.set_double_variables(np.array([control_curve,]))
for initial_volume in (0.0, 10.0, 50.0, 80.0, 90.0, 100.0):
s.initial_volume = initial_volume
model.run()
開發(fā)者ID:pywr,項(xiàng)目名稱:pywr,代碼行數(shù):38,
示例18: gen_reg_from_xy
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def gen_reg_from_xy(xy, w):
xy = xy[np.argsort(xy[:, 0])]
return np.interp(np.arange(w), xy[:, 0], xy[:, 1], period=w)
開發(fā)者ID:sunset1995,項(xiàng)目名稱:HorizonNet,代碼行數(shù):5,
示例19: _resample_numpy
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def _resample_numpy(signal, desired_length):
resampled_signal = np.interp(
np.linspace(0.0, 1.0, desired_length, endpoint=False), # where to interpolate
np.linspace(0.0, 1.0, len(signal), endpoint=False), # known positions
signal, # known data points
)
return resampled_signal
開發(fā)者ID:neuropsychology,項(xiàng)目名稱:NeuroKit,代碼行數(shù):9,
示例20: __call__
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def __call__(self, env, agent, step):
value = np.interp(step,
[1, self.total_steps],
[self.start_value, self.stop_value])
self.setter(env, agent, value)
開發(fā)者ID:chainer,項(xiàng)目名稱:chainerrl,代碼行數(shù):7,
示例21: __getitem__
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def __getitem__(self, query):
"""Given query, returns the interpolated function value."""
return np.interp(query, self.inputs, self.outputs)
開發(fā)者ID:zykls,項(xiàng)目名稱:whynot,代碼行數(shù):5,
示例22: test_exceptions
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_exceptions(self):
assert_raises(ValueError, interp, 0, [], [])
assert_raises(ValueError, interp, 0, [0], [1, 2])
assert_raises(ValueError, interp, 0, [0, 1], [1, 2], period=0)
assert_raises(ValueError, interp, 0, [], [], period=360)
assert_raises(ValueError, interp, 0, [0], [1, 2], period=360)
開發(fā)者ID:Frank-qlu,項(xiàng)目名稱:recruit,代碼行數(shù):8,
示例23: test_basic
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_basic(self):
x = np.linspace(0, 1, 5)
y = np.linspace(0, 1, 5)
x0 = np.linspace(0, 1, 50)
assert_almost_equal(np.interp(x0, x, y), x0)
開發(fā)者ID:Frank-qlu,項(xiàng)目名稱:recruit,代碼行數(shù):7,
示例24: test_right_left_behavior
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_right_left_behavior(self):
# Needs range of sizes to test different code paths.
# size ==1 is special cased, 1 < size < 5 is linear search, and
# size >= 5 goes through local search and possibly binary search.
for size in range(1, 10):
xp = np.arange(size, dtype=np.double)
yp = np.ones(size, dtype=np.double)
incpts = np.array([-1, 0, size - 1, size], dtype=np.double)
decpts = incpts[::-1]
incres = interp(incpts, xp, yp)
decres = interp(decpts, xp, yp)
inctgt = np.array([1, 1, 1, 1], dtype=float)
dectgt = inctgt[::-1]
assert_equal(incres, inctgt)
assert_equal(decres, dectgt)
incres = interp(incpts, xp, yp, left=0)
decres = interp(decpts, xp, yp, left=0)
inctgt = np.array([0, 1, 1, 1], dtype=float)
dectgt = inctgt[::-1]
assert_equal(incres, inctgt)
assert_equal(decres, dectgt)
incres = interp(incpts, xp, yp, right=2)
decres = interp(decpts, xp, yp, right=2)
inctgt = np.array([1, 1, 1, 2], dtype=float)
dectgt = inctgt[::-1]
assert_equal(incres, inctgt)
assert_equal(decres, dectgt)
incres = interp(incpts, xp, yp, left=0, right=2)
decres = interp(decpts, xp, yp, left=0, right=2)
inctgt = np.array([0, 1, 1, 2], dtype=float)
dectgt = inctgt[::-1]
assert_equal(incres, inctgt)
assert_equal(decres, dectgt)
開發(fā)者ID:Frank-qlu,項(xiàng)目名稱:recruit,代碼行數(shù):39,
示例25: test_scalar_interpolation_point
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_scalar_interpolation_point(self):
x = np.linspace(0, 1, 5)
y = np.linspace(0, 1, 5)
x0 = 0
assert_almost_equal(np.interp(x0, x, y), x0)
x0 = .3
assert_almost_equal(np.interp(x0, x, y), x0)
x0 = np.float32(.3)
assert_almost_equal(np.interp(x0, x, y), x0)
x0 = np.float64(.3)
assert_almost_equal(np.interp(x0, x, y), x0)
x0 = np.nan
assert_almost_equal(np.interp(x0, x, y), x0)
開發(fā)者ID:Frank-qlu,項(xiàng)目名稱:recruit,代碼行數(shù):15,
示例26: test_non_finite_behavior
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_non_finite_behavior(self):
x = [1, 2, 2.5, 3, 4]
xp = [1, 2, 3, 4]
fp = [1, 2, np.inf, 4]
assert_almost_equal(np.interp(x, xp, fp), [1, 2, np.inf, np.inf, 4])
fp = [1, 2, np.nan, 4]
assert_almost_equal(np.interp(x, xp, fp), [1, 2, np.nan, np.nan, 4])
開發(fā)者ID:Frank-qlu,項(xiàng)目名稱:recruit,代碼行數(shù):9,
示例27: test_if_len_x_is_small
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_if_len_x_is_small(self):
xp = np.arange(0, 10, 0.0001)
fp = np.sin(xp)
assert_almost_equal(np.interp(np.pi, xp, fp), 0.0)
開發(fā)者ID:Frank-qlu,項(xiàng)目名稱:recruit,代碼行數(shù):6,
示例28: test_period
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def test_period(self):
x = [-180, -170, -185, 185, -10, -5, 0, 365]
xp = [190, -190, 350, -350]
fp = [5, 10, 3, 4]
y = [7.5, 5., 8.75, 6.25, 3., 3.25, 3.5, 3.75]
assert_almost_equal(np.interp(x, xp, fp, period=360), y)
x = np.array(x, order='F').reshape(2, -1)
y = np.array(y, order='C').reshape(2, -1)
assert_almost_equal(np.interp(x, xp, fp, period=360), y)
開發(fā)者ID:Frank-qlu,項(xiàng)目名稱:recruit,代碼行數(shù):11,
示例29: get_brain_regions
?點(diǎn)贊 5
?
# 需要導(dǎo)入模塊: import numpy [as 別名]
# 或者: from numpy import interp [as 別名]
def get_brain_regions(xyz, channels_positions=SITES_COORDINATES, brain_atlas=brat, display=False):
"""
:param xyz: numpy array of 3D coordinates corresponding to a picked track or a trajectory
the deepest point is considered the tip.
:param channels:
:param DISPLAY:
:return:
"""
"""
this is the depth along the probe (from the first point which is the deepest labeled point)
Due to the blockiness, depths may not be unique along the track so it has to be prepared
"""
d = atlas.cart2sph(xyz[:, 0] - xyz[0, 0], xyz[:, 1] - xyz[0, 1], xyz[:, 2] - xyz[0, 2])[0]
ind_depths = np.argsort(d)
d = np.sort(d)
iid = np.where(np.diff(d) >= 0)[0]
ind_depths = ind_depths[iid]
d = d[iid]
"""
Interpolate channel positions along the probe depth and get brain locations
"""
xyz_channels = np.zeros((channels_positions.shape[0], 3))
for m in np.arange(3):
xyz_channels[:, m] = np.interp(channels_positions[:, 1] / 1e6,
d[ind_depths], xyz[ind_depths, m])
brain_regions = brain_atlas.regions.get(brat.get_labels(xyz_channels))
"""
Get the best linear fit probe trajectory using points cloud
"""
track = atlas.Trajectory.fit(xyz)
return brain_regions, track
開發(fā)者ID:int-brain-lab,項(xiàng)目名稱:ibllib,代碼行數(shù):37,
注:本文中的numpy.interp方法示例整理自Github/MSDocs等源碼及文檔管理平臺(tái),相關(guān)代碼片段篩選自各路編程大神貢獻(xiàn)的開源項(xiàng)目,源碼版權(quán)歸原作者所有,傳播和使用請(qǐng)參考對(duì)應(yīng)項(xiàng)目的License;未經(jīng)允許,請(qǐng)勿轉(zhuǎn)載。
總結(jié)
以上是生活随笔為你收集整理的pythoninterp error_Python numpy.interp方法代码示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java接收rowtype类型_Java
- 下一篇: html扩展xhtml在线,告别html