473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1578
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out...
2
by: Tim Rowe | last post by:
Does numarray-0.5.win32-py2.2.exe work with Python 2.3? If not, is there a version that will? Tia, Tim
0
by: Colin J. Williams | last post by:
numarray is a package which is under development and intended to replace Numeric, an efficient and operational package. One of the classes in numarray is NumArray. As currently implemented,...
3
by: Alexander Schwaigkofler | last post by:
Hi! I have the following problem with numarray. I read the install.txt manual, but it doesn't already work. OS: Microsoft Windows 2000 python: Python 2.2.3 (#42, May 30 2003, 18:12:08) on...
8
by: Russell E. Owen | last post by:
I'm writing a C extension for numarray and am puzzled about the idiom for error handling. The documentation seems to say one should always decref an array after calling NA_InputArray, etc., to...
3
by: Alex Hunsley | last post by:
I'm looking for a way to iterate over all the items in a numarray. Writing a few nested loops isn't going to cut it, because the numarray in question could be of any dimension... I am aware of the...
11
by: grv | last post by:
So it is supposed to be very fast to have an array of say 5 million integers stored in a binary file and do a = numarray.fromfile('filename', (2, 2, 2)) numarray.add(a, 9, a) but how is that...
1
by: Chris P. | last post by:
Hi. I have a very simple task to perform and I'm having a hard time doing it. Given an array called 'x' (created using the numarray library), is there a single command that rounds each of its...
10
by: Bryan | last post by:
hi, what is the difference among numeric, numpy and numarray? i'm going to start using matplotlib soon and i'm not sure which one i should use. this page says, "Numarray is a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.