0

I need help with square root and powers. I am calculating the mean errors and I have been told to do this for each element:

dmgfeerr = sqrt(dmgherr**2 - dfeherr**2).

but I get an error message: TypeError: only size-1 arrays can be converted to Python scalars.

Below is the data. Its something called quadrature error :

        dfeh = d[1].data['Fe_H_2']
        dmgh = d[1].data['MG_H']
        dnh = d[1].data['N_H']
        dch = d[1].data['C_H']
        dalh = d[1].data['AL_H']
        dmnh = d[1].data['MN_H']

        dcfe = (dch) - (dfeh)
        dnfe = (dnh) - (dfeh)
        dalfe = (dalh) - (dfeh)
        dmnfe = (dmnh) -(dfeh)
        dmgfe = (dmgh) - (dfeh)

        dfeherr = d[1].data['FE_H_ERR_2']
        dmgherr = d[1].data['MG_H_ERR']
        dalherr = d[1].data['AL_H_ERR']
        dcherr = d[1].data['C_H_ERR']
        dnherr = d[1].data['N_H_ERR']
        dmnherr =d[1].data['MN_H_ERR']


        dcfeerr = dcherr - dfeherr
        dnfeerr = dnherr - dfeherr
        dalfeerr = dalherr - dfeherr
        dmnfeerr = dmnherr - dfeherr
        dmgfeerr = dmgherr - dfeherr
Iguananaut
  • 21,810
  • 5
  • 50
  • 63
  • 1
    Probably your data is of type `list` or maybe `numpy.ndarray`. If you are using the `sqrt` from the math-package, it cannot handle that data type directly. either you loop over the data yourself or you use the `numpy.sqrt()`. Moreover, you'll have problems with the square and the difference of lists. Can you provide the `type`? – mikuszefski Aug 26 '20 at 06:44
  • 1
    What `sqrt` are you using? What was the import statement. You're probably using `math.sqrt` instead of `numpy.sqrt`. Only the math functions in the `numpy` package know how to work properly on numpy arrays. – Iguananaut Aug 26 '20 at 09:12
  • Does this answer your question? [TypeError: only size-1 arrays can be converted to Python scalars arrives during a simple program](https://stackoverflow.com/questions/58452146/typeerror-only-size-1-arrays-can-be-converted-to-python-scalars-arrives-during) – Iguananaut Aug 26 '20 at 09:20

0 Answers0