本文整理汇总了Python中numpy.core.shape函数的典型用法代码示例。如果您正苦于以下问题:Python shape函数的具体用法?Python shape怎么用?Python shape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shape函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hfft
def hfft(a, n=None, axis=-1):
"""
Compute the fft of a signal which spectrum has Hermitian symmetry.
Parameters
----------
a : array
input array
n : int
length of the hfft
axis : int
axis over which to compute the hfft
See also
--------
rfft
ihfft
Notes
-----
These are a pair analogous to rfft/irfft, but for the
opposite case: here the signal is real in the frequency domain and has
Hermite symmetry in the time domain. So here it's hermite_fft for which
you must supply the length of the result if it is to be odd.
ihfft(hfft(a), len(a)) == a
within numerical accuracy.
"""
a = asarray(a).astype(complex)
if n is None:
n = (shape(a)[axis] - 1) * 2
return irfft(conjugate(a), n, axis) * n
示例2: ihfft
def ihfft(a, n=None, axis=-1):
"""
Compute the inverse fft of a signal whose spectrum has Hermitian symmetry.
Parameters
----------
a : array_like
Input array.
n : int, optional
Length of the ihfft.
axis : int, optional
Axis over which to compute the ihfft.
See also
--------
rfft, hfft
Notes
-----
These are a pair analogous to rfft/irfft, but for the
opposite case: here the signal is real in the frequency domain and has
Hermite symmetry in the time domain. So here it's hermite_fft for which
you must supply the length of the result if it is to be odd.
ihfft(hfft(a), len(a)) == a
within numerical accuracy.
"""
a = asarray(a).astype(float)
if n is None:
n = shape(a)[axis]
return conjugate(rfft(a, n, axis))/n
示例3: graAscent02
def graAscent02(dataMatIn, labelMatIn):
dataMatrix = array(dataMatIn)
m, n = shape(dataMatIn)
alpha = 0.01
weights = ones(n)
for i in range(m):
h = sigmod(sum(dataMatrix[i] * weights))
err = labelMatIn[i] - h
offset = alpha * err * dataMatrix[i]
weights = weights + offset
return weights
示例4: graAscent01
def graAscent01(dataMatIn, labelMatIn):
dataMatrix = mat(dataMatIn)
labelMatrix = mat(labelMatIn).transpose()
m, n = shape(dataMatrix)
alpha = 0.0001
maxCycle = 500
weights = ones((n, 1))
for k in range(maxCycle):
h = sigmod(dataMatrix * weights)
err = labelMatrix - h
weights = weights + alpha * dataMatrix.transpose() * err
return weights
示例5: ihfft
def ihfft(a, n=None, axis=-1):
"""
Compute the inverse FFT of a signal which has Hermitian symmetry.
Parameters
----------
a : array_like
Input array.
n : int, optional
Length of the inverse FFT.
Number of points along transformation axis in the input to use.
If `n` is smaller than the length of the input, the input is cropped.
If it is larger, the input is padded with zeros. If `n` is not given,
the length of the input along the axis specified by `axis` is used.
axis : int, optional
Axis over which to compute the inverse FFT. If not given, the last
axis is used.
Returns
-------
out : complex ndarray
The truncated or zero-padded input, transformed along the axis
indicated by `axis`, or the last one if `axis` is not specified.
If `n` is even, the length of the transformed axis is ``(n/2)+1``.
If `n` is odd, the length is ``(n+1)/2``.
See also
--------
hfft, irfft
Notes
-----
`hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the
opposite case: here the signal has Hermitian symmetry in the time domain
and is real in the frequency domain. So here it's `hfft` for which
you must supply the length of the result if it is to be odd:
``ihfft(hfft(a), len(a)) == a``, within numerical accuracy.
Examples
--------
>>> spectrum = np.array([ 15, -4, 0, -1, 0, -4])
>>> np.fft.ifft(spectrum)
array([ 1.+0.j, 2.-0.j, 3.+0.j, 4.+0.j, 3.+0.j, 2.-0.j])
>>> np.fft.ihfft(spectrum)
array([ 1.-0.j, 2.-0.j, 3.-0.j, 4.-0.j])
"""
a = asarray(a).astype(float)
if n is None:
n = shape(a)[axis]
return conjugate(rfft(a, n, axis))/n
示例6: graAscent03
def graAscent03(dataMatIn, labelMatIn):
dataMatrix = array(dataMatIn)
m, n = shape(dataMatIn)
weights = ones(n)
numIter = 15
for j in range(numIter):
dataIndex = range(m)
for i in range(m):
alpha = 4.0 / (i + j + 1.0) + 0.001
randIndex = int(random.uniform(0, len(dataIndex)))
h = sigmod(sum(dataMatrix[randIndex] * weights))
err = labelMatIn[randIndex] - h
weights = weights + alpha * err * dataMatrix[randIndex]
return weights
示例7: hfft
def hfft(a, n=None, axis=-1):
"""
Compute the FFT of a signal whose spectrum has Hermitian symmetry.
Parameters
----------
a : array_like
The input array.
n : int, optional
The length of the FFT.
axis : int, optional
The axis over which to compute the FFT, assuming Hermitian symmetry
of the spectrum. Default is the last axis.
Returns
-------
out : ndarray
The transformed input.
See also
--------
rfft : Compute the one-dimensional FFT for real input.
ihfft : The inverse of `hfft`.
Notes
-----
`hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the
opposite case: here the signal is real in the frequency domain and has
Hermite symmetry in the time domain. So here it's `hfft` for which
you must supply the length of the result if it is to be odd:
``ihfft(hfft(a), len(a)) == a``, within numerical accuracy.
Examples
--------
>>> signal = np.array([[1, 1.j], [-1.j, 2]])
>>> np.conj(signal.T) - signal # check Hermitian symmetry
array([[ 0.-0.j, 0.+0.j],
[ 0.+0.j, 0.-0.j]])
>>> freq_spectrum = np.fft.hfft(signal)
>>> freq_spectrum
array([[ 1., 1.],
[ 2., -2.]])
"""
a = asarray(a).astype(complex)
if n is None:
n = (shape(a)[axis] - 1) * 2
return irfft(conjugate(a), n, axis) * n
示例8: ihfft
def ihfft(a, n=None, axis=-1):
"""hfft(a, n=None, axis=-1)
ihfft(a, n=None, axis=-1)
These are a pair analogous to rfft/irfft, but for the
opposite case: here the signal is real in the frequency domain and has
Hermite symmetry in the time domain. So here it's hfft for which
you must supply the length of the result if it is to be odd.
ihfft(hfft(a), len(a)) == a
within numerical accuracy."""
a = asarray(a).astype(float)
if n == None:
n = shape(a)[axis]
return conjugate(rfft(a, n, axis))/n
示例9: ifft
def ifft(a, n=None, axis=-1):
"""
Compute the one-dimensonal inverse fft along an axis.
Return the `n` point inverse discrete Fourier transform of `a`. The length
`n` defaults to the length of `a`. If `n` is larger than the length of `a`,
then `a` will be zero-padded to make up the difference. If `n` is smaller
than the length of `a`, then `a` will be truncated to reduce its size.
Parameters
----------
a : array_like
Input array.
n : int, optional
Length of the fft.
axis : int, optional
Axis over which to compute the inverse fft.
See Also
--------
fft
Notes
-----
The input array is expected to be packed the same way as the output of
fft, as discussed in the fft documentation.
This is the inverse of fft: ifft(fft(a)) == a within numerical
accuracy.
This is most efficient for `n` a power of two. This also stores a cache of
working memory for different sizes of fft's, so you could theoretically
run into memory problems if you call this too many times with too many
different `n` values.
"""
a = asarray(a).astype(complex)
if n is None:
n = shape(a)[axis]
return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftb, _fft_cache) / n
示例10: irfft
def irfft(a, n=None, axis=-1):
"""
Compute the one-dimensional inverse fft for real input.
Parameters
----------
a : array
Input array with real data type.
n : int
Length of the fft.
axis : int
Axis over which to compute the fft.
See Also
--------
rfft
Notes
-----
Return the real valued `n` point inverse discrete Fourier transform
of `a`, where `a` contains the nonnegative frequency terms of a
Hermite-symmetric sequence. `n` is the length of the result, not the
input. If `n` is not supplied, the default is 2*(len(`a`)-1). If you
want the length of the result to be odd, you have to say so.
If you specify an `n` such that `a` must be zero-padded or truncated, the
extra/removed values will be added/removed at high frequencies. One can
thus resample a series to m points via Fourier interpolation by: a_resamp
= irfft(rfft(a), m).
Within numerical accuracy ``irfft`` is the inverse of ``rfft``::
irfft(rfft(a), len(a)) == a
"""
a = asarray(a).astype(complex)
if n is None:
n = (shape(a)[axis] - 1) * 2
return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftb, _real_fft_cache) / n
示例11: irfft
def irfft(a, n=None, axis=-1):
"""irfft(a, n=None, axis=-1)
Return the real valued n point inverse discrete Fourier transform
of a, where a contains the nonnegative frequency terms of a
Hermite-symmetric sequence. n is the length of the result, not the
input. If n is not supplied, the default is 2*(len(a)-1). If you
want the length of the result to be odd, you have to say so.
If you specify an n such that a must be zero-padded or truncated, the
extra/removed values will be added/removed at high frequencies. One can
thus resample a series to m points via Fourier interpolation by: a_resamp
= irfft(rfft(a), m).
This is the inverse of rfft:
irfft(rfft(a), len(a)) == a
within numerical accuracy."""
a = asarray(a).astype(complex)
if n == None:
n = (shape(a)[axis] - 1) * 2
return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftb,
_real_fft_cache) / n
示例12: ihfft
def ihfft(a, n=None, axis=-1):
"""
Compute the inverse FFT of a signal whose spectrum has Hermitian symmetry.
Parameters
----------
a : array_like
Input array.
n : int, optional
Length of the inverse FFT.
axis : int, optional
Axis over which to compute the inverse FFT, assuming Hermitian
symmetry of the spectrum. Default is the last axis.
Returns
-------
out : ndarray
The transformed input.
See also
--------
hfft, irfft
Notes
-----
`hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the
opposite case: here the signal is real in the frequency domain and has
Hermite symmetry in the time domain. So here it's `hfft` for which
you must supply the length of the result if it is to be odd:
``ihfft(hfft(a), len(a)) == a``, within numerical accuracy.
"""
a = asarray(a).astype(float)
if n is None:
n = shape(a)[axis]
return conjugate(rfft(a, n, axis))/n
示例13: ifft
def ifft(a, n=None, axis=-1):
"""ifft(a, n=None, axis=-1)
Return the n point inverse discrete Fourier transform of a. n
defaults to the length of a. If n is larger than the length of a,
then a will be zero-padded to make up the difference. If n is
smaller than the length of a, then a will be truncated to reduce
its size.
The input array is expected to be packed the same way as the output of
fft, as discussed in it's documentation.
This is the inverse of fft: ifft(fft(a)) == a within numerical
accuracy.
This is most efficient for n a power of two. This also stores a cache of
working memory for different sizes of fft's, so you could theoretically
run into memory problems if you call this too many times with too many
different n's."""
a = asarray(a).astype(complex)
if n == None:
n = shape(a)[axis]
return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftb, _fft_cache) / n
示例14: irfft
def irfft(a, n=None, axis=-1):
"""
Compute the inverse of the n-point DFT for real input.
This function computes the inverse of the one-dimensional *n*-point
discrete Fourier Transform of real input computed by `rfft`.
In other words, `irfft(rfft(a), len(a)) == a` to within numerical accuracy.
(See Notes below for why `len(a)` is necessary here.)
The input is expected to be in the form returned by `rfft`, i.e. the
real zero-frequency term followed by the complex positive frequency terms
in order of increasing frequency. Since the discrete Fourier Transform of
real input is Hermite-symmetric, the negative frequency terms are taken
to be the complex conjugates of the corresponding positive frequency terms.
Parameters
----------
a : array_like
Input array
n : int, optional
Length of the transformed axis of the output.
For `n` output points, `n/2+1` input points are necessary. If the
input is longer than this, it is cropped. If it is shorter than this,
it is padded with zeros. If `n` is not given, it is determined from
the length of the input (along the axis specified by `axis`)
as explained below.
axis : int, optional
Axis over which to compute the inverse FFT.
Returns
-------
out : real ndarray
The truncated or zero-padded input, transformed along the axis
indicated by `axis`, or the last one if `axis` is not specified.
The length of the transformed axis is `n`, or, if `n` is not given,
`2*(m-1)` where `m` is the length of the transformed axis of the input.
To get an odd number of output points, `n` must be specified.
Raises
------
IndexError
if `axis` is larger than the last axis of `a`
See Also
--------
numpy.fft : for definition of the DFT and conventions used
rfft : The one-dimensional FFT of real input, of which `irfft` is inverse.
fft : The one-dimensional FFT
irfft2 : The inverse of the two-dimensional FFT of real input.
irfftn : The inverse of the *n*-dimensional FFT of real input.
Notes
-----
Returns the real valued `n`-point inverse discrete Fourier transform
of `a`, where `a` contains the nonnegative frequency terms of a
Hermite-symmetric sequence. `n` is the length of the result, not the
input.
If you specify an `n` such that `a` must be zero-padded or truncated, the
extra/removed values will be added/removed at high frequencies. One can
thus resample a series to `m` points via Fourier interpolation by:
`a_resamp = irfft(rfft(a), m)`.
Examples
--------
>>> from numpy.fft import ifft, irfft
>>> ifft([1, -1j, -1, 1j])
array([ 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j])
>>> irfft([1, -1j, -1])
array([ 0., 1., 0., 0.])
Notice how the last term in the input to the ordinary `ifft` is the
complex conjugate of the second term, and the output has zero imaginary
part everywhere. When calling `irfft`, the negative frequencies are not
specified, and the output array is purely real.
"""
a = asarray(a).astype(complex)
if n is None:
n = (shape(a)[axis] - 1) * 2
return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftb,
_real_fft_cache) / n
示例15: ifft
def ifft(a, n=None, axis=-1):
"""
Compute the one-dimensional inverse discrete Fourier Transform
This function computes the inverse of the one-dimensional *n*-point
discrete Fourier transform computed by `fft`. In other words,
`ifft(fft(a)) == a` to within numerical accuracy.
For a general description of the algorithm and definitions,
see `numpy.fft`.
The input should be ordered in the same way as is returned by `fft`,
i.e., `a[0]` should contain the zero frequency term,
`a[1:n/2+1]` should contain the positive-frequency terms, and
`a[n/2+1:]` should contain the negative-frequency terms, in order of
decreasingly negative frequency. See `numpy.fft` for details.
Parameters
----------
a : array_like
Input array, can be complex
n : int, optional
Length of the transformed axis of the output.
If `n` is smaller than the length of the input, the input is cropped.
If it is larger, the input is padded with zeros. If `n` is not given,
the length of the input (along the axis specified by `axis`) is used.
See notes about padding issues.
axis : int, optional
Axis over which to compute the inverse DFT. If not given, the last
axis is used.
Returns
-------
out : complex ndarray
The truncated or zero-padded input, transformed along the axis
indicated by `axis`, or the last one if `axis` is not specified.
Raises
------
IndexError
if `axes` is larger than the last axis of `a`
See Also
--------
numpy.fft : An introduction, with definitions and general explanations
fft : The one-dimensional (forward) FFT, of which `ifft` is the inverse
ifft2 : The two-dimensional inverse FFT
ifftn : The n-dimensional inverse FFT
Notes
-----
If the input parameter `n` is larger than the size of the input, the input
is padded by appending zeros at the end. Even though this is the common
approach, it might lead to surprising results. If a different padding is
desired, it must be performed before calling `ifft`.
Examples
--------
>>> from numpy.fft import ifft
>>> ifft([0, 4, 0, 0])
array([ 1.+0.j, 0.+1.j, -1.+0.j, 0.-1.j])
>>> from numpy import exp, pi, arange, zeros
>>> import matplotlib.pyplot as plt
>>> t = arange(400)
>>> n = zeros((400,), dtype=complex)
>>> n[40:60] = exp(1j*np.random.uniform(0, 2*pi, (20,)))
>>> s = np.fft.ifft(n)
>>> plt.plot(t, s.real, 'b-', t, s.imag, 'r--')
>>> plt.legend(('real', 'imaginary'))
>>> plt.show()
Creates and plots a band-limited signal with random phases.
"""
a = asarray(a).astype(complex)
if n is None:
n = shape(a)[axis]
return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftb, _fft_cache) / n