Scipy: vectorized function does not take scalars as arguments

Discussion in 'Python' started by ago, May 24, 2006.

  1. ago

    ago Guest

    Once I vectorize a function it does not acccept scalars anymore. Es

    def f(x): return x*2
    vf = vectorize(f)
    print vf(2)

    AttributeError: 'int' object has no attribute 'astype'

    Is this the intended behaviour?
    ago, May 24, 2006
    #1
    1. Advertising

  2. ago

    Robert Kern Guest

    ago wrote:
    > Once I vectorize a function it does not acccept scalars anymore. Es
    >
    > def f(x): return x*2
    > vf = vectorize(f)
    > print vf(2)
    >
    > AttributeError: 'int' object has no attribute 'astype'
    >
    > Is this the intended behaviour?


    More or less. It would be nice if it transparently handled the scalars, too, so
    if you would like to work on that, we'd be happy to incorporate your changes.

    --
    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, May 24, 2006
    #2
    1. Advertising

  3. ago wrote:
    > Once I vectorize a function it does not acccept scalars anymore. Es
    >
    > def f(x): return x*2
    > vf = vectorize(f)
    > print vf(2)
    >
    > AttributeError: 'int' object has no attribute 'astype'
    >
    > Is this the intended behaviour?
    >


    Vectorize handles scalars in recent versions of NumPy. Which version do
    you have?

    -Travis
    Travis E. Oliphant, May 24, 2006
    #3
  4. ago

    ago Guest

    I have installed numpy-0.9.6 I haven't tried 0.9.8.
    ago, May 25, 2006
    #4
    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. Paxcal
    Replies:
    0
    Views:
    1,814
    Paxcal
    Feb 11, 2004
  2. Steven Watanabe
    Replies:
    0
    Views:
    293
    Steven Watanabe
    May 4, 2006
  3. vml
    Replies:
    3
    Views:
    674
  4. Nathan Rice
    Replies:
    10
    Views:
    340
    Ethan Furman
    Dec 21, 2011
  5. Nathan Rice
    Replies:
    4
    Views:
    220
    Nathan Rice
    Dec 21, 2011
Loading...

Share This Page