469,920 Members | 2,355 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

numarray

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
Import Numeric
I get


indicating that numarray is installed correctly.

What am I doing wrong?

Thanks in advance

Ben
Jul 18 '05 #1
4 2912
> if I just enter
Import Numeric
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 *
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Diez B. Roggisch wrote:
if I just enter

>Import Numeric


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


Actually,

import numarray

Note the case. In addition,

import Numeric

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

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Jul 18 '05 #3
Ben Champion wrote:
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:
import numarray
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.
Jul 18 '05 #4
>
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...

--
Regards,

Diez B. Roggisch
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by RJS | last post: by
3 posts views Thread by Alexander Schwaigkofler | last post: by
4 posts views Thread by Marco Bubke | last post: by
4 posts views Thread by Marco Bubke | last post: by
2 posts views Thread by Marc Schellens | last post: by
3 posts views Thread by SunX | last post: by
3 posts views Thread by Mizrandir | last post: by
reply views Thread by andrewfelch | last post: by
10 posts views Thread by Bryan | last post: by
reply views Thread by robert | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.