Colin J. Williams
cjw at sympatico.ca
Tue Jul 20 01:03:33 CEST 2004
Jean Brouwers wrote:
> You probably meant
> xyz = lambda x,y,z: float(x*y*z)
> or maybe even
> xyz = lambda x,y,z: float(x)*float(y)*float(z)
> /Jean Brouwers
You are right, I overlooked SunX's wish to have a Float array.
Unfortunately, numarray assumes that the source is based in
the function indices, which delivers an Int array.
Thus, your suggestion raises an exception. An alternative
is given below.
xyz= lambda x,y,z: x*y*z
# This raises an exception
##xur = numarray.fromfunction(xyz, (6, 4, 3))
## File "C:\Python23\Lib\site-packages\numarray\numarraycore.py", line
715, in __float__
## raise TypeError, "Only rank-0 numarray can be cast to floats."
# This gets around that problem
ind= numarray.indices(shape= (6, 4, 3), type= numarray.Float)
xur= apply(xyz, ind)
> In article <2fCKc.1152$Vw3.217821 at news20.bellglobal.com>, Colin J.
> Williams <cjw at sympatico.ca> wrote:
>>>I tried to initialize a float point array by:
>>>xur = numarray.fromfunction(lambda x,y,z:x*y*z, (2, 2, 2))
>>>but I ended up with an integer array even though x, y, and z are all floats.
>>>BTW, how do you unzip NumTut in windows? And is there a newer version?
>>You might try something like:
>>xyz= lambda x,y,z:x*y*z
>>xur = numarray.fromfunction(xyz, (6, 6, 3))
More information about the Python-list