[Numpy-discussion] Convolve returning zero array
Peter Verveer
verveer at embl-heidelberg.de
Tue Dec 16 01:55:05 CST 2003
Hi Remco,
> OK, here is the example:
[code deleted]
> When I run this code, the first convolution gives an array of zeros, the
> second convolution is good.
The problem is that the output of the convolve functions (both the convolve
and the nd_image versions) return the result with the same type as the input.
In your first case the input was of Bool type and thus the result could only
be 0 or 1. Conversion to Float64 before calculation seems to fix the problem.
(I inserted 'data1 = inputarray(data1, Float64)' before the function call.)
Alternatively in nd_image.convolve1d you can use the output_type flag to save
you the conversion.
> I also did a quick try with convolve from nd_image, but this function was
> slower than the convolve from numarray with a large Gaussian distribution.
Yes, nd_image convolve is designed for the general multi-dimensional case and
may therefore be slower in some cases. Also I think the convolve version uses
an internal conversion of the input to double type which appears to faster.
The nd_image version does not do that because for large multi-dimensional
arrays that may cost a lot of memory. I think if you do the conversion to
Float64 before the speed should be closer. For one-dimensional cases, you
should probably just stick to the convolve version.
I hope this solved your problem.
Cheers, Peter
--
Dr. Peter J. Verveer
Cell Biology and Cell Biophysics Programme
European Molecular Biology Laboratory
Meyerhofstrasse 1
D-69117 Heidelberg
Germany
Tel. : +49 6221 387245
Fax : +49 6221 387306
More information about the Numpy-discussion
mailing list