Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2351 > unrolled thread

Mathematical Operations on Array

Started by"Bryan.Fodness@gmail.com" <bryan.fodness@gmail.com>
First post2011-04-01 06:35 -0700
Last post2011-04-01 15:49 -0400
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Mathematical Operations on Array "Bryan.Fodness@gmail.com" <bryan.fodness@gmail.com> - 2011-04-01 06:35 -0700
    Re: Mathematical Operations on Array Peter Otten <__peter__@web.de> - 2011-04-01 15:52 +0200
      Re: Mathematical Operations on Array "Bryan.Fodness@gmail.com" <bryan.fodness@gmail.com> - 2011-04-01 07:00 -0700
    Re: Mathematical Operations on Array Terry Reedy <tjreedy@udel.edu> - 2011-04-01 15:49 -0400

#2351 — Mathematical Operations on Array

From"Bryan.Fodness@gmail.com" <bryan.fodness@gmail.com>
Date2011-04-01 06:35 -0700
SubjectMathematical Operations on Array
Message-ID<decec810-5909-4a2e-a682-13979a8046f5@t13g2000vbo.googlegroups.com>
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?

[toc] | [next] | [standalone]


#2352

FromPeter Otten <__peter__@web.de>
Date2011-04-01 15:52 +0200
Message-ID<mailman.74.1301665981.2990.python-list@python.org>
In reply to#2351
Bryan.Fodness@gmail.com 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'>


[toc] | [prev] | [next] | [standalone]


#2354

From"Bryan.Fodness@gmail.com" <bryan.fodness@gmail.com>
Date2011-04-01 07:00 -0700
Message-ID<5964b78e-8791-4f3c-8d87-5caef177b28c@v8g2000yqb.googlegroups.com>
In reply to#2352
On Apr 1, 9:52 am, Peter Otten <__pete...@web.de> wrote:
> Bryan.Fodn...@gmail.com 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.

[toc] | [prev] | [next] | [standalone]


#2393

FromTerry Reedy <tjreedy@udel.edu>
Date2011-04-01 15:49 -0400
Message-ID<mailman.97.1301687709.2990.python-list@python.org>
In reply to#2351
On 4/1/2011 9:35 AM, Bryan.Fodness@gmail.com 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web