numarray

Discussion in 'Python' started by Ben Champion, Nov 18, 2004.

  1. Ben Champion

    Ben Champion Guest

    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
     
    Ben Champion, Nov 18, 2004
    #1
    1. Advertisements

  2. > 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
     
    Diez B. Roggisch, Nov 18, 2004
    #2
    1. Advertisements

  3. Ben Champion

    Robert Kern Guest

    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


    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter
     
    Robert Kern, Nov 18, 2004
    #3
  4. 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.
     
    Roberto Antonio Ferreira De Almeida, Nov 18, 2004
    #4
  5. >
    > 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
     
    Diez B. Roggisch, Nov 18, 2004
    #5
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RJS
    Replies:
    0
    Views:
    556
  2. Tim Rowe

    Numarray for Python 2.3

    Tim Rowe, Jul 16, 2003, in forum: Python
    Replies:
    2
    Views:
    404
    Tim Rowe
    Jul 16, 2003
  3. Thomas Heller

    Re: py2exe and numarray

    Thomas Heller, Aug 8, 2003, in forum: Python
    Replies:
    0
    Views:
    454
    Thomas Heller
    Aug 8, 2003
  4. Eugene Druker

    numarray.linear_algebra.eigenvectors bug ?

    Eugene Druker, Sep 19, 2003, in forum: Python
    Replies:
    1
    Views:
    390
    John J. Lee
    Sep 20, 2003
  5. Colin J. Williams

    Sub-classing NumArray - two questions

    Colin J. Williams, Oct 1, 2003, in forum: Python
    Replies:
    0
    Views:
    311
    Colin J. Williams
    Oct 1, 2003
Loading...

Share This Page