numarray

B

Ben Champion

I have installed python 2.3.3 on my windows machine have have ran
several programs succesfully. I have also installed numarray 1.1 for
my version of python and am now trying to create arrays using the
array command, eg
Import Numeric
a = array([1, 2, 3])

Traceback (most recent call last):
File "<pyshell#1>", line 1, in -toplevel-
a = array([1, 2, 3])
NameError: name 'array' is not defined

if I just enter

I get

indicating that numarray is installed correctly.

What am I doing wrong?

Thanks in advance

Ben
 
D

Diez B. Roggisch

if I just enter
I get


indicating that numarray is installed correctly.

What am I doing wrong?

I doubt that that works. "Import" won't do it - it yields a syntax error.

What you meant is

import Numarray

But you have to keep in mind that importing a module that way will not put
it in the global namespace. So you have to qualify function names:

Numarray.array

Or you import them using the "from" syntax, which will bind the Numarray
names in the global namespace:

from Numarray import *
 
R

Robert Kern

Diez said:
I doubt that that works. "Import" won't do it - it yields a syntax error.

What you meant is

import Numarray

Actually,

import numarray

Note the case. In addition,

import Numeric

will import Numeric, not numarray. But otherwise, Diez is correct.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
R

Roberto Antonio Ferreira De Almeida

Ben said:
I have installed python 2.3.3 on my windows machine have have ran
several programs succesfully. I have also installed numarray 1.1 for
my version of python and am now trying to create arrays using the
array command, eg
Import Numeric
a = array([1, 2, 3])

These are two different modules: numarray is one, and Numeric is the
other. If you installed numarray, you should use:

Also note the lowercase 'import'.

As another poster pointed out, the 'array' function is not in the global
namespace. You have to use:
>>> a = numarray.array([1,2,3])

Or alternatively:
>>> from numarray import *
>>> a = array([1,2,3])

What I usually do, since Numeric and numarray are mostly compatible is:

try:
import numarray as N
except ImportError:
import Numeric as N

a = N.array([1,2,3])

This way you'll use numarray if it is available, otherwise you fallback
to Numeric.
 
D

Diez B. Roggisch

Actually,

import numarray

Note the case. In addition,

import Numeric

will import Numeric, not numarray. But otherwise, Diez is correct.

I actually _used_ Numeric as that is what is installed on my machine :) So I
couldn't verify that Numarray is not working...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top