Mathematical Operations on Array

Discussion in 'Python' started by Bryan.Fodness@gmail.com, Apr 1, 2011.

  1. Guest

    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?
     
    , Apr 1, 2011
    #1
    1. Advertising

  2. Peter Otten Guest

    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'>
     
    Peter Otten, Apr 1, 2011
    #2
    1. Advertising

  3. Guest

    On Apr 1, 9:52 am, Peter Otten <> wrote:
    > 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.
     
    , Apr 1, 2011
    #3
  4. Terry Reedy Guest

    On 4/1/2011 9:35 AM, 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
     
    Terry Reedy, Apr 1, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MtnSurf8

    Mathematical Operations in VHDL

    MtnSurf8, Apr 25, 2004, in forum: VHDL
    Replies:
    1
    Views:
    5,920
    Egbert Molenkamp
    Apr 25, 2004
  2. Replies:
    0
    Views:
    388
  3. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,306
    robert
    Feb 11, 2006
  4. Replies:
    11
    Views:
    829
  5. Romeo Kienzler
    Replies:
    0
    Views:
    528
    Romeo Kienzler
    Jul 30, 2009
Loading...

Share This Page