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

N

nure123

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
 
R

Robert Kern

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
 
S

Steve Holden

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
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top