本文整理汇总了Python中numpy.sinc方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.sinc方法的具体用法?Python numpy.sinc怎么用?Python numpy.sinc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.sinc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lanczos
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def lanczos(dx, a=3):
"""Lanczos kernel
Parameters
----------
dx: float
amount to shift image
a: int
Lanczos window size parameter
Returns
-------
result: array-like
1D Lanczos kernel
"""
if np.abs(dx) > 1:
raise ValueError("The fractional shift dx must be between -1 and 1")
window = np.arange(-a + 1, a + 1) + np.floor(dx)
y = np.sinc(dx - window) * np.sinc((dx - window) / a)
return y, window.astype(int)
示例2: test_projected_incumbent_estimation
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def test_projected_incumbent_estimation(self):
X = np.random.randn(20, 10)
y = np.sinc(X).sum(axis=1)
class DemoModel(object):
def train(self, X, y):
self.X = X
self.y = y
def predict(self, X):
return self.y, np.ones(self.y.shape[0])
model = DemoModel()
model.train(X, y)
inc, inc_val = incumbent_estimation.projected_incumbent_estimation(model, X, proj_value=1)
b = np.argmin(y)
assert inc[-1] == 1
assert np.all(inc[:-1] == X[b])
assert inc_val == y[b]
示例3: setUp
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def setUp(self):
X_task_1 = np.random.rand(10, 2)
y_task_1 = np.sinc(X_task_1 * 10 - 5).sum(axis=1)
X_task_1 = np.concatenate((X_task_1, np.zeros([10, 1])), axis=1)
X_task_2 = np.random.rand(10, 2)
y_task_2 = np.sinc(X_task_2 * 2 - 4).sum(axis=1)
X_task_2 = np.concatenate((X_task_2, np.ones([10, 1])), axis=1)
X_task_3 = np.random.rand(10, 2)
y_task_3 = np.sinc(X_task_3 * 8 - 6).sum(axis=1)
X_task_3 = np.concatenate((X_task_3, 2 * np.ones([10, 1])), axis=1)
self.X = np.concatenate((X_task_1, X_task_2, X_task_3), axis=0)
self.y = np.concatenate((y_task_1, y_task_2, y_task_3), axis=0)
self.model = WrapperBohamiann()
self.model.train(self.X, self.y)
示例4: expmap_to_quaternion
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def expmap_to_quaternion(e):
"""
Convert axis-angle rotations (aka exponential maps) to quaternions.
Stable formula from "Practical Parameterization of Rotations Using the Exponential Map".
Expects a tensor of shape (*, 3), where * denotes any number of dimensions.
Returns a tensor of shape (*, 4).
"""
assert e.shape[-1] == 3
original_shape = list(e.shape)
original_shape[-1] = 4
e = e.reshape(-1, 3)
theta = np.linalg.norm(e, axis=1).reshape(-1, 1)
w = np.cos(0.5*theta).reshape(-1, 1)
xyz = 0.5*np.sinc(0.5*theta/np.pi)*e
return np.concatenate((w, xyz), axis=1).reshape(original_shape)
示例5: main
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def main():
"""Test driver"""
# From pp. 149-150
x = np.ones(21)
p = q = 1
print('x: {}\np: {}\nq: {}'.format(x,p,q))
b,a,err = prony(x, p, q)
print('a: {}\nb: {}\nerr: {}'.format(a,b,err))
# From pp. 152-153
# Note that these results don't match the book, but they do match the
# MATLAB version. So I'm either setting things up wrong or this is an
# errata in the book.
p = q = 5
nd = 5
n = np.arange(11)
i = np.sinc((n-nd)/2)/2
b,a,err = prony(i, p, q)
print('a: {}\nb: {}\nerr: {}'.format(a,b,err))
示例6: test_fraunhofer_propagation_rectangular
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def test_fraunhofer_propagation_rectangular():
for num_pix in [512, 1024]:
pupil_grid = make_pupil_grid(num_pix)
focal_grid = make_focal_grid(16, 8)
for size in [[1,1], [0.75,1], [0.75,0.75]]:
aperture = evaluate_supersampled(rectangular_aperture(size), pupil_grid, 8)
for focal_length in [1, 1.3]:
prop = FraunhoferPropagator(pupil_grid, focal_grid, focal_length=focal_length)
for wavelength in [1, 0.8]:
wf = Wavefront(aperture, wavelength)
img = prop(wf).electric_field
img /= img[np.argmax(np.abs(img))]
k_x, k_y = np.array(size) / wavelength / focal_length
reference = (np.sinc(k_x * focal_grid.x) * np.sinc(k_y * focal_grid.y))
if num_pix == 512:
assert np.abs(img - reference).max() < 5e-5
elif num_pix == 1024:
assert np.abs(img - reference).max() < 2e-5
else:
assert False # This should never happen.
示例7: CompensateTSC
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def CompensateTSC(w, v):
"""
Return the Fourier-space kernel that accounts for the convolution of
the gridded field with the TSC window function in configuration space.
.. note::
see equation 18 (with p=3) of
`Jing et al 2005 <https://arxiv.org/abs/astro-ph/0409240>`_
Parameters
----------
w : list of arrays
the list of "circular" coordinate arrays, ranging from
:math:`[-\pi, \pi)`.
v : array_like
the field array
"""
for i in range(3):
wi = w[i]
tmp = (numpy.sinc(0.5 * wi / numpy.pi) ) ** 3
v = v / tmp
return v
示例8: CompensatePCS
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def CompensatePCS(w, v):
"""
Return the Fourier-space kernel that accounts for the convolution of
the gridded field with the PCS window function in configuration space.
.. note::
see equation 18 (with p=4) of
`Jing et al 2005 <https://arxiv.org/abs/astro-ph/0409240>`_
Parameters
----------
w : list of arrays
the list of "circular" coordinate arrays, ranging from
:math:`[-\pi, \pi)`.
v : array_like
the field array
"""
for i in range(3):
wi = w[i]
tmp = (numpy.sinc(0.5 * wi / numpy.pi) ) ** 4
v = v / tmp
return v
示例9: CompensateCIC
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def CompensateCIC(w, v):
"""
Return the Fourier-space kernel that accounts for the convolution of
the gridded field with the CIC window function in configuration space
.. note::
see equation 18 (with p=2) of
`Jing et al 2005 <https://arxiv.org/abs/astro-ph/0409240>`_
Parameters
----------
w : list of arrays
the list of "circular" coordinate arrays, ranging from
:math:`[-\pi, \pi)`.
v : array_like
the field array
"""
for i in range(3):
wi = w[i]
tmp = (numpy.sinc(0.5 * wi / numpy.pi) ) ** 2
tmp[wi == 0.] = 1.
v = v / tmp
return v
示例10: sincinterp
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def sincinterp(x):
"""
Sinc interpolation for computation of fractional transformations.
As appears in :
-https://github.com/audiolabs/frft/
----------
Args:
f : (array) Complex valued input array
a : (float) Alpha factor
Returns:
ret : (array) Real valued synthesised data
"""
N = len(x)
y = np.zeros(2 * N - 1, dtype=x.dtype)
y[:2 * N:2] = x
xint = fftconvolve( y[:2 * N], np.sinc(np.arange(-(2 * N - 3), (2 * N - 2)).T / 2),)
return xint[2 * N - 3: -2 * N + 3]
示例11: fractional_delay
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def fractional_delay(t0):
"""
Creates a fractional delay filter using a windowed sinc function.
The length of the filter is fixed by the module wide constant
`frac_delay_length` (default 81).
Parameters
----------
t0: float
The delay in fraction of sample. Typically between -1 and 1.
Returns
-------
numpy array
A fractional delay filter with specified delay.
"""
N = constants.get("frac_delay_length")
return np.hanning(N) * np.sinc(np.arange(N) - (N - 1) / 2 - t0)
示例12: _get_taper_eigenvalues
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def _get_taper_eigenvalues(tapers, half_bandwidth, time_index):
'''Finds the eigenvalues of the original spectral concentration
problem using the autocorr sequence technique from Percival and Walden,
1993 pg 390
Parameters
----------
tapers : array, shape (n_tapers, n_time_samples_per_window)
half_bandwidth : float
time_index : array, (n_time_samples_per_window,)
Returns
-------
eigenvalues : array, shape (n_tapers,)
'''
ideal_filter = 4 * half_bandwidth * np.sinc(
2 * half_bandwidth * time_index)
ideal_filter[0] = 2 * half_bandwidth
n_time_samples_per_window = len(time_index)
return np.dot(
_auto_correlation(tapers)[:, :n_time_samples_per_window],
ideal_filter)
示例13: val_exp
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def val_exp(B_val):
"""
Fast implementation of the translation and rotation specific exp function
"""
t_val = imt_func(B_val, no.value)
phiP_val = B_val - mult_with_ninf(t_val)
phi = np.sqrt(-float(gmt_func(phiP_val, phiP_val)[0]))
P_val = phiP_val / phi
P_n_val = gmt_func(P_val, I3.value)
t_nor_val = gmt_func(imt_func(t_val, P_n_val), P_n_val)
t_par_val = t_val - t_nor_val
coef_val = np.sin(phi) * P_val
coef_val[0] += np.cos(phi)
R_val = coef_val + gmt_func(coef_val, mult_with_ninf(t_nor_val)) + \
np.sinc(phi/np.pi) * mult_with_ninf(t_par_val)
return R_val
示例14: conv_receiver_slit
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def conv_receiver_slit(self):
"""
compute the rectangular convolution for the receiver slit or SiPSD
pixel size
Returns
-------
array-like
the convolver
"""
me = self.get_function_name() # the name of the convolver, as a string
# The receiver slit convolution is a top-hat of angular half-width
# a=(slit_width/2)/diffractometer_radius
# which has Fourier transform of sin(a omega)/(a omega)
# NOTE! numpy's sinc(x) is sin(pi x)/(pi x), not sin(x)/x
if self.param_dicts[me].get("slit_width", None) is None:
return None
epsr = (self.param_dicts["conv_receiver_slit"]["slit_width"] /
self.param_dicts["conv_global"]["diffractometer_radius"])
return self.general_tophat(me, epsr)
示例15: design_windowed_sinc_lpf
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sinc [as 别名]
def design_windowed_sinc_lpf(fc, bw):
N = Filter.get_filter_length_from_bandwidth(bw)
# Compute sinc filter impulse response
h = np.sinc(2 * fc * (np.arange(N) - (N - 1) / 2.))
# We use blackman window function
w = np.blackman(N)
# Multiply sinc filter with window function
h = h * w
# Normalize to get unity gain
h_unity = h / np.sum(h)
return h_unity