本文整理汇总了Python中numpy.core.take函数的典型用法代码示例。如果您正苦于以下问题:Python take函数的具体用法?Python take怎么用?Python take使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了take函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ifftshift
def ifftshift(x,axes=None):
"""
Inverse of fftshift.
Parameters
----------
x : array_like
Input array.
axes : int or shape tuple, optional
Axes over which to calculate. Defaults to None which is over all axes.
See Also
--------
fftshift
"""
tmp = asarray(x)
ndim = len(tmp.shape)
if axes is None:
axes = range(ndim)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = n-(n+1)/2
mylist = concatenate((arange(p2,n),arange(p2)))
y = take(y,mylist,k)
return y
示例2: fftshift
def fftshift(x,axes=None):
"""
Shift zero-frequency component to center of spectrum.
This function swaps half-spaces for all axes listed (defaults to all).
If len(x) is even then the Nyquist component is y[0].
Parameters
----------
x : array_like
Input array.
axes : int or shape tuple, optional
Axes over which to shift. Default is None which shifts all axes.
See Also
--------
ifftshift
"""
tmp = asarray(x)
ndim = len(tmp.shape)
if axes is None:
axes = range(ndim)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = (n+1)/2
mylist = concatenate((arange(p2,n),arange(p2)))
y = take(y,mylist,k)
return y
示例3: fftshift
def fftshift(x, axes=None):
"""
Shift the zero-frequency component to the center of the spectrum.
This function swaps half-spaces for all axes listed (defaults to all).
Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even.
Parameters
----------
x : array_like
Input array.
axes : int or shape tuple, optional
Axes over which to shift. Default is None, which shifts all axes.
Returns
-------
y : ndarray
The shifted array.
See Also
--------
ifftshift : The inverse of `fftshift`.
Examples
--------
>>> freqs = np.fft.fftfreq(10, 0.1)
>>> freqs
array([ 0., 1., 2., 3., 4., -5., -4., -3., -2., -1.])
>>> np.fft.fftshift(freqs)
array([-5., -4., -3., -2., -1., 0., 1., 2., 3., 4.])
Shift the zero-frequency component only along the second axis:
>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
>>> freqs
array([[ 0., 1., 2.],
[ 3., 4., -4.],
[-3., -2., -1.]])
>>> np.fft.fftshift(freqs, axes=(1,))
array([[ 2., 0., 1.],
[-4., 3., 4.],
[-1., -3., -2.]])
"""
tmp = asarray(x)
ndim = len(tmp.shape)
if axes is None:
axes = list(range(ndim))
elif isinstance(axes, (int, nt.integer)):
axes = (axes,)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = (n+1)//2
mylist = concatenate((arange(p2,n),arange(p2)))
y = take(y,mylist,k)
return y
示例4: original_fftshift
def original_fftshift(x, axes=None):
""" How fftshift was implemented in v1.14"""
tmp = asarray(x)
ndim = tmp.ndim
if axes is None:
axes = list(range(ndim))
elif isinstance(axes, integer_types):
axes = (axes,)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = (n + 1) // 2
mylist = concatenate((arange(p2, n), arange(p2)))
y = take(y, mylist, k)
return y
示例5: ifftshift
def ifftshift(x,axes=None):
""" ifftshift(x,axes=None) - > y
Inverse of fftshift.
"""
tmp = asarray(x)
ndim = len(tmp.shape)
if axes is None:
axes = range(ndim)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = n-(n+1)/2
mylist = concatenate((arange(p2,n),arange(p2)))
y = take(y,mylist,k)
return y
示例6: ifftshift
def ifftshift(x, axes=None):
"""
The inverse of `fftshift`. Although identical for even-length `x`, the
functions differ by one sample for odd-length `x`.
Parameters
----------
x : array_like
Input array.
axes : int or shape tuple, optional
Axes over which to calculate. Defaults to None, which shifts all axes.
Returns
-------
y : ndarray
The shifted array.
See Also
--------
fftshift : Shift zero-frequency component to the center of the spectrum.
Examples
--------
>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
>>> freqs
array([[ 0., 1., 2.],
[ 3., 4., -4.],
[-3., -2., -1.]])
>>> np.fft.ifftshift(np.fft.fftshift(freqs))
array([[ 0., 1., 2.],
[ 3., 4., -4.],
[-3., -2., -1.]])
"""
tmp = asarray(x)
ndim = len(tmp.shape)
if axes is None:
axes = list(range(ndim))
elif isinstance(axes, integer_types):
axes = (axes,)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = n-(n+1)//2
mylist = concatenate((arange(p2, n), arange(p2)))
y = take(y, mylist, k)
return y
示例7: _cook_nd_args
def _cook_nd_args(a, s=None, axes=None, invreal=0):
if s is None:
shapeless = 1
if axes is None:
s = list(a.shape)
else:
s = take(a.shape, axes)
else:
shapeless = 0
s = list(s)
if axes is None:
axes = range(-len(s), 0)
if len(s) != len(axes):
raise ValueError, "Shape and axes have different lengths."
if invreal and shapeless:
s[axes[-1]] = (s[axes[-1]] - 1) * 2
return s, axes
示例8: ifftshift
def ifftshift(x, axes=None):
"""
The inverse of fftshift.
Parameters
----------
x : array_like
Input array.
axes : int or shape tuple, optional
Axes over which to calculate. Defaults to None, which shifts all axes.
Returns
-------
y : ndarray
The shifted array.
See Also
--------
fftshift : Shift zero-frequency component to the center of the spectrum.
Examples
--------
>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
>>> freqs
array([[ 0., 1., 2.],
[ 3., 4., -4.],
[-3., -2., -1.]])
>>> np.fft.ifftshift(np.fft.fftshift(freqs))
array([[ 0., 1., 2.],
[ 3., 4., -4.],
[-3., -2., -1.]])
"""
tmp = asarray(x)
ndim = len(tmp.shape)
if axes is None:
axes = range(ndim)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = n - (n + 1) / 2
mylist = concatenate((arange(p2, n), arange(p2)))
y = take(y, mylist, k)
return y
示例9: _cook_nd_args
def _cook_nd_args(a, s=None, axes=None, invreal=0):
if s is None:
shapeless = 1
if axes is None:
s = list(a.shape)
else:
s = take(a.shape, axes)
else:
shapeless = 0
s = list(s)
if axes is None:
axes = range(-len(s), 0)
if len(s) != len(axes):
raise ValueError("Shape and axes have different lengths.")
if invreal and shapeless:
# Here is the fix. The following line is replaced
# (see numpy commit 88a02920daf0b408086106439c53bd488e73af29):
#s[axes[-1]] = (s[axes[-1]] - 1) * 2
s[-1] = (a.shape[axes[-1]] - 1) * 2
return s, axes
示例10: fftshift
def fftshift(x,axes=None):
""" fftshift(x, axes=None) -> y
Shift zero-frequency component to center of spectrum.
This function swaps half-spaces for all axes listed (defaults to all).
Notes:
If len(x) is even then the Nyquist component is y[0].
"""
tmp = asarray(x)
ndim = len(tmp.shape)
if axes is None:
axes = range(ndim)
y = tmp
for k in axes:
n = tmp.shape[k]
p2 = (n+1)/2
mylist = concatenate((arange(p2,n),arange(p2)))
y = take(y,mylist,k)
return y