[SciPy-user] convolve2d.. or Numeric to numarray conversion

Perry Greenfield scipy-user@scipy.net
Fri, 14 Feb 2003 10:11:45 -0500

> Hi!
> I would like to do a 2D convolution. And as it seems there is a nice 
> convolve2d in the Convolve package that comes with numarray, 
> which doesn't 
> seem available for Numeric or for SciPy.
> The conversion from Numeric arrays to numarray arrays works fine with 1D 
> arrays (numarray.array(list(a))). But for 2D arrays it gives me:
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File 
> "/usr/local/lib/python2.2/site-packages/numarray/numarray.py", line 
> 313, in array
>     return fromlist(buffer, type, shape)
>   File 
> "/usr/local/lib/python2.2/site-packages/numarray/numarray.py", line 
> 265, in fromlist
>     arr.fromlist(seq)
> TypeError: NA_setFromPythonScalar: bad value type.
> Is there another easy way to convert Numeric arrays to numarray 
> arrays? (And 
> the reverse would also be handy to have, but that's for later.)
Yes, but I don't think there is a current way for multidimensional
arrays that doesn't require you to manually pass along shape information
(though it would be trivial to write a function to do so. We've talked
about making numarray and Numeric arrays being aware of each other, 
but haven't done anything yet about it. In any case, you can do what
you did above after flattening the array (list only works on the 
first dimension, the reason it fails is that it returns a list
of 1-d Numeric arrays) and then reshaping the resultant 1-d
numarray array. Or you should be able to use tostring and fromstring
as long as you provide the necessary type and shape information
to fromstring.

We will get around to making numarray more Numeric aware eventually
(currently we are working on improving small array performance).

Thanks, Perry Greenfield