Scipy: vectorized function does not take scalars as arguments

A

ago

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?
 
R

Robert Kern

ago said:
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
 
T

Travis E. Oliphant

ago said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top