By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,117 Members | 2,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,117 IT Pros & Developers. It's quick & easy.

numarray

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
> 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

P: n/a
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

P: n/a
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

P: n/a
>
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.