boxcar computes a 1-D or 2-D boxcar filter on every 1-D or
2-D subarray of data. boxshape is a tuple of integers
specifying the dimensions of the filter, e.g. (3,3). If
output is specified, it should be the same shape as
data and the result will be stored in it. In that case
None will be returned.
mode can be any of the following values:
nearest
: Elements beyond boundary come from nearest edge pixel.
wrap
: Elements beyond boundary come from the opposite array
edge.
reflect
: Elements beyond boundary come from reflection on same
array edge.
constant
: Elements beyond boundary are set to what is specified
in cval, an optional numerical parameter; the default value is
0.0.
>>> print a
[1 5 4 7 2 9 3 6]
>>> print conv.boxcar(a,(3,))
[ 2.33333333 3.33333333 5.33333333 4.33333333 6. 4.66666667
6. 5. ]
# for even number box size, it will take the extra point from the lower end
>>> print conv.boxcar(a,(2,))
[ 1. 3. 4.5 5.5 4.5 5.5 6. 4.5]
convolve(
data, kernel, mode=FULL)
Returns the discrete, linear convolution of 1-D sequences data
and kernel; mode can be VALID, SAME,
or FULL to specify the size of the resulting sequence. See section
15.2.
Return the 2-dimensional convolution of data and
kernel. If output is not None, the result is
stored in output and None is returned. fft is
used to switch between FFT-based convolution and the naive algorithm,
defaulting to naive. Using fft mode becomes more beneficial as
the size of the kernel grows; for small kernels, the naive algorithm is more
efficient. mode has the same choices as those of
boxcar. A number of storage considerations come into play with
large arrays: (1) boundary modes are implemented by making an oversized
temporary copy of the data array which has a shape equal to the
sum of the data and kernel shapes. (2) likewise, the
kernel is copied into an array with the same shape as the
oversized data array. (3) In FFT mode, the fourier transforms of
the data and kernel arrays are stored in double
precision complex temporaries. The aggregate effect is that storage roughly
equal to a factor of eight (x2 from 2 and x4 from 3) times the size of the
data is required to compute the convolution of a Float32
data array.
correlate(
data, kernel, mode=FULL)
Return the cross-correlation of data and kernel;
mode can be VALID, SAME, or FULL to
specify the size of the resulting sequence. correlate is
very closely related to convolve in implementation.
See section 15.2.
Return the 2-dimensional convolution of data and
kernel. If output is not None, the result is
stored in output and None is returned. fft is
used to switch between FFT-based convolution and the naive algorithm,
defaulting to naive. Using fft mode becomes more beneficial as
the size of the kernel grows; for small kernels, the naive algorithm is more
efficient. mode has the same choices as those of
boxcar. See also convolve2d for notes regarding
storage consumption.
Note:cross_correlate is deprecated and should not be used.