Mathematical Operations on Array

B

Bryan.Fodness

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?
 
P

Peter Otten

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:
<ufunc 'arccos'>
 
B

Bryan.Fodness

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:

<ufunc 'arccos'>- Hide quoted text -

- Show quoted text -

Thank you.
 
T

Terry Reedy

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.
 

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
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top