Search code examples
pythonmathlogarithm

How to do a calculation with Python with logarithm?


I want to calculate some values with math.log() but it doesn't work and I don't no why. Here is my first code:

import os
os.getcwd()
import pandas as pd
import loaddata as ld
import symmetryvalues as sv
import numpy as np

#%% Laden der Daten für Symmetriewerte
dataListStep = ld.loadData("../data/mpi/onlycsv/StepData")
indexStepData = 1
stepData = dataListStep[indexStepData]

leftMean = np.asarray([stepData.iloc[:, i].mean() for i in range(0, 5)])
rightMean = np.asarray([stepData.iloc[:, i].mean() for i in range(5, 10)])

#%% Calculation of Mean Values
dataFrameStepLeftMean = pd.DataFrame({'leftMean': leftMean})
dataFrameStepRightMean = pd.DataFrame({'rightMean': rightMean})
#
symGaitAsym = sv.gaitAsymmetry(dataFrameStepLeftMean.leftMean, dataFrameStepRightMean.rightMean)
print("Das Ergebnis für Gait Asymmetry über die Mittelwerte lautet: " +str(symGaitAsym))

Here is the code for the formula:

import math as m

def gaitAsymmetry(L, R):
    r = (m.log(R/L))*100
    return r

This is my Error in my Output:

raise TypeError("cannot convert the series to " "{0}".format(str(converter)))
TypeError: cannot convert the series to <class 'float'>

My test data is:

data = """

1.00,0.80,0.40,0.20,0.50,1.20,0.90,0.30,0.20,0.34

1.10,0.85,0.50,0.21,0.59,1.30,0.95,0.40,0.21,0.42

0.90,0.90,0.45,0.23,0.50,1.10,1.00,0.35,0.23,0.35

1.05,0.70,0.40,0.28,0.57,1.25,0.80,0.30,0.28,0.38

0.95,0.75,0.45,0.30,0.60,1.15,0.85,0.35,0.30,0.42

"""

Could someone explain what's the problem and how I can solve this, please? Thanks for helping me.


Solution

  • Use numpy.log instead of math.log. math.log cannot calculate logarithm of an array but numpy can.