469,923 Members | 1,528 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

numarray question

I tried to initialize a float point array by:

import numarray
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?

Thank you
Howard
Jul 18 '05 #1
3 1462
SunX wrote:
I tried to initialize a float point array by:

import numarray
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?

Thank you
Howard

You might try something like:

import numarray
xyz= lambda x,y,z:x*y*z
xur = numarray.fromfunction(xyz, (6, 6, 3))
print xur

Jul 18 '05 #2


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

In article <2f*******************@news20.bellglobal.com>, Colin J.
Williams <cj*@sympatico.ca> wrote:
SunX wrote:
I tried to initialize a float point array by:

import numarray
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?

Thank you
Howard

You might try something like:

import numarray
xyz= lambda x,y,z:x*y*z
xur = numarray.fromfunction(xyz, (6, 6, 3))
print xur

Jul 18 '05 #3


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

Jean,

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.

Colin W.

import numarray
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)
print xur


In article <2f*******************@news20.bellglobal.com>, Colin J.
Williams <cj*@sympatico.ca> wrote:

SunX wrote:
I tried to initialize a float point array by:

import numarray
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?

Thank you
Howard


You might try something like:

import numarray
xyz= lambda x,y,z:x*y*z
xur = numarray.fromfunction(xyz, (6, 6, 3))
print xur


Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by RJS | last post: by
2 posts views Thread by Tim Rowe | last post: by
reply views Thread by Colin J. Williams | last post: by
3 posts views Thread by Alexander Schwaigkofler | last post: by
8 posts views Thread by Russell E. Owen | last post: by
3 posts views Thread by Alex Hunsley | last post: by
11 posts views Thread by grv | last post: by
10 posts views Thread by Bryan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.