Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Mathematical Operations on Array

Reply
Thread Tools

Mathematical Operations on Array

 
 
Bryan.Fodness@gmail.com
Guest
Posts: n/a
 
      04-01-2011
I am loading text into an array and would like to convert the values.

from math import *
from numpy import *
from pylab import *

data=loadtxt('raw.dat')
mincos=degrees(acos(data[:,0]))
minazi=degrees(data[:,1])
minthick=data[:,2]/0.006858

I am not sure why degrees() works, but acos() does not.

I receive the following

Traceback (most recent call last):
File "C:\ test.py", line 6, in ?
mincos=degrees(acos(float(data[:,0])))
TypeError: only length-1 arrays can be converted to Python scalars

Can anyone tell me what I am doing wrong?
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      04-01-2011
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I am loading text into an array and would like to convert the values.
>
> from math import *
> from numpy import *
> from pylab import *
>
> data=loadtxt('raw.dat')
> mincos=degrees(acos(data[:,0]))
> minazi=degrees(data[:,1])
> minthick=data[:,2]/0.006858
>
> I am not sure why degrees() works, but acos() does not.
>
> I receive the following
>
> Traceback (most recent call last):
> File "C:\ test.py", line 6, in ?
> mincos=degrees(acos(float(data[:,0])))
> TypeError: only length-1 arrays can be converted to Python scalars
>
> Can anyone tell me what I am doing wrong?


Using star-imports.

Among other things it makes it hard to keep track of where things are coming
from:

>>> from math import *
>>> from numpy import *
>>> degrees

<ufunc 'degrees'>
>>> acos

<built-in function acos>
>>> acos.__module__

'math'
>>> arccos

<ufunc 'arccos'>



 
Reply With Quote
 
 
 
 
Bryan.Fodness@gmail.com
Guest
Posts: n/a
 
      04-01-2011
On Apr 1, 9:52*am, Peter Otten <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > I am loading text into an array and would like to convert the values.

>
> > from math import *
> > from numpy import *
> > from pylab import *

>
> > data=loadtxt('raw.dat')
> > mincos=degrees(acos(data[:,0]))
> > minazi=degrees(data[:,1])
> > minthick=data[:,2]/0.006858

>
> > I am not sure why degrees() *works, but acos() does not.

>
> > I receive the following

>
> > Traceback (most recent call last):
> > * File "C:\ test.py", line 6, in ?
> > * * mincos=degrees(acos(float(data[:,0])))
> > TypeError: only length-1 arrays can be converted to Python scalars

>
> > Can anyone tell me what I am doing wrong?

>
> Using star-imports.
>
> Among other things it makes it hard to keep track of where things are coming
> from:
>
> >>> from math import *
> >>> from numpy import *
> >>> degrees

> <ufunc 'degrees'>
> >>> acos

>
> <built-in function acos>>>> acos.__module__
> 'math'
> >>> arccos

>
> <ufunc 'arccos'>- Hide quoted text -
>
> - Show quoted text -


Thank you.
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      04-01-2011
On 4/1/2011 9:35 AM, (E-Mail Removed) wrote:

> Can anyone tell me what I am doing wrong?


Posting the same question twice is a bad idea, as it splits answers and
may lead to duplication. I answered your first post without seeing
Peter's response to you second post, which is further down the list.


--
Terry Jan Reedy

 
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
Re: Mathematical set operations in Java / searching for library Romeo Kienzler Java 0 07-30-2009 10:28 AM
Mathematical set operations in Java / searching for library mowsen@googlemail.com Java 11 11-10-2007 08:06 PM
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
Rowfilters Mathematical Representation thecameleon06@hotmail.com ASP .Net 0 11-14-2005 08:52 AM
Mathematical Operations in VHDL MtnSurf8 VHDL 1 04-25-2004 06:07 AM



Advertisments