numarray

Roberto Antonio Ferreira De Almeida roberto at dealmeida.net
Thu Nov 18 11:19:59 EST 2004


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.



More information about the Python-list mailing list