Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > TypeError: only length-1 arrays can be converted to Python scalars.

Reply
Thread Tools

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

 
 
nure123@gmail.com
Guest
Posts: n/a
 
      02-28-2008
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
 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      02-28-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      02-28-2008
(E-Mail Removed) 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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Two arrays: return only values that exist in both arrays? Joshua Muheim Ruby 8 11-23-2007 07:04 PM
How can I make a class that can be converted into an int? Matthew Wilson Python 4 10-02-2006 03:17 PM
compilation error only in published version (converted to asp.net 2.0) rsphere@gmail.com ASP .Net 1 01-10-2006 03:53 PM
Indented text converted to arrays of arrays Brad Baxter Perl Misc 2 06-30-2004 04:38 PM



Advertisments