TypeError: only length-1 arrays can be converted to Python scalars.

Discussion in 'Python' started by nure123@gmail.com, Feb 28, 2008.

  1. Guest

    Hi All,

    Could anybody tell me what is the problem with the following sequence
    with which I always get the above error message. I use Numeric and
    Python 2.4

    x=array([1,2,3,4])
    y=exp(x)

    Nure
     
    , Feb 28, 2008
    #1
    1. Advertising

  2. Robert Kern Guest

    Re: TypeError: only length-1 arrays can be converted to Pythonscalars.

    wrote:
    > Hi All,
    >
    > Could anybody tell me what is the problem with the following sequence
    > with which I always get the above error message. I use Numeric and
    > Python 2.4
    >
    > x=array([1,2,3,4])
    > y=exp(x)


    Presumably, you are using exp() from the builtin module math, which knows
    nothing about Numeric. Use Numeric.exp() instead.

    I do recommend upgrading to numpy and asking further questions on the numpy
    mailing list.

    http://www.scipy.org/Mailing_Lists

    When reporting an error, please include the smallest *complete* snippet of code
    that demonstrates the problem, as well as the complete traceback.

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Feb 28, 2008
    #2
    1. Advertising

  3. Steve Holden Guest

    Re: TypeError: only length-1 arrays can be converted to Pythonscalars.

    wrote:
    > Hi All,
    >
    > Could anybody tell me what is the problem with the following sequence
    > with which I always get the above error message. I use Numeric and
    > Python 2.4
    >
    > x=array([1,2,3,4])
    > y=exp(x)


    The meaning of the error message is fairly obvious - exp() can't operate
    on arrays. I presume Numeric has its own exp(), and that you need to use
    that instead.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Feb 28, 2008
    #3
    1. Advertising

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. Achim Domma
    Replies:
    3
    Views:
    4,593
    Alex Martelli
    Oct 14, 2003
  2. Replies:
    2
    Views:
    4,722
  3. Brad Baxter

    Indented text converted to arrays of arrays

    Brad Baxter, Jun 29, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    112
    Brad Baxter
    Jun 30, 2004
  4. Oscar Benjamin
    Replies:
    0
    Views:
    161
    Oscar Benjamin
    Sep 21, 2013
  5. Jai
    Replies:
    2
    Views:
    164
    Peter Otten
    Dec 13, 2013
Loading...

Share This Page