[GRASS-user] Read/Write numpy array

Glynn Clements glynn at gclements.plus.com
Wed Apr 6 16:34:06 EDT 2011


Johannes Radinger wrote:

> Thank you for your answer but I still get an error, although I changed the code
> which is now:
>     x = garray.array()
>     x.read("distance_raster")
>     Density = garray.array()
>     Density[...] = p * stats.norm.pdf(x,loc=m, scale=s1*K) + (1-p) * stats.norm.pdf(x, loc=m, scale=s2*K)
>     Density.write("Density")
> 
> the error says:
>    Density[...] = p * stats.norm.pdf(x,loc=m, scale=s1*K) +
> (1-p) * stats.norm.pdf(x, loc=m, scale=s2*K)
>   File "/Library/Frameworks/Python.framework/Versions/2.6/li
> b/python2.6/site-packages/scipy/stats/distributions.py",
> line 1104, in pdf
>     x = arr((x-loc)*1.0/scale)
> TypeError: unsupported operand type(s) for /:
> 'numpy.ndarray' and 'numpy.ndarray'
> 
> 
> Propably it has something to do with the stats-norm function of scipy which is working
> with numpy array (maybe not with the garray)..or what does that error mean?

garray.array is a subclass of numpy.memmap which itself is a subclass
of numpy.ndarray. You should be able to use a garray.array anywhere
you can use a numpy array.

But I don't think that has anything to do with the error message,
which suggests that both arguments are plain numpy arrays.

I can't even import scipy.stats here; possibly because SciPy is out of
date with respect to my Python version. I'll have another look when
I've updated SciPy.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list