473,687 Members | 3,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

numarray question

I tried to initialize a float point array by:

import numarray
xur = numarray.fromfu nction(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 1593
SunX wrote:
I tried to initialize a float point array by:

import numarray
xur = numarray.fromfu nction(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.fromfu nction(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.fromfu nction(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.fromfu nction(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.fromfu nction(xyz, (6, 4, 3))
## File "C:\Python23\Li b\site-packages\numarr ay\numarraycore .py", line
715, in __float__
## raise TypeError, "Only rank-0 numarray can be cast to floats."
# This gets around that problem
ind= numarray.indice s(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.fromfu nction(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.fromfu nction(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
2987
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 "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google. py2exe output is last.
2
1908
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
1471
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, instances of this class are instantiated using factory functions. This appears to restrict the sub-classing of NumArray Examples: a sub-class Matrix, an array restricted to two dimensions, or a sub-class Mix, which combines the NumArray with...
3
1824
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 win32 numarray: Version 0.7 the output from the installation (by hand) you can see below:
8
1792
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 convert numarray args to C arrays. However, the example and also the numarray code suggests that it's OK to return early via (for example) PyErr_Format without doing the DECREF. For example, I have appended a very abbreviated version of the...
3
1698
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 revel function, but that appears to just flatten the numarray. What I need is an iterator that can give each value and the coordinates in the array of that item.... thanks alex
11
1984
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 faster than reading the entire file into memory and then having a for loop in C: (loop over range) { *p++ += 9 }
1
3211
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 elements to the nearest integer? I've already tried something like >>> x_rounded = x.astype(numarray.Int) but that only truncates each element (i.e. '5.9' becomes '5'). I've read over all the relevant numarray documentation, and it
10
2224
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 re-implementation of an older Python array module called Numeric" http://www.stsci.edu/resources/software_hardware/numarray
0
9072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8786
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6453
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5807
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4321
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4547
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.