python - scipy.stats.pearsonr with lists of Decimals? -


trying run scipy.stats.pearsonr 2 lists of decimal making scipy unhappy:

print type(signals) print type(signals[0]) print type(prices) print type(prices[0])  <type 'list'> <class 'decimal.decimal'> <type 'list'> <class 'decimal.decimal'>  correlation = stats.pearsonr(signals, prices)  traceback (most recent call last):    file "commod.py", line 74, in <module>     main()   file "commod.py", line 69, in main     correlation = stats.pearsonr(signals, prices)   file "/home/.../venv/local/lib/python2.7/site-packages/scipy/stats/stats.py", line 2445, in pearsonr     t_squared = r*r * (df / ((1.0 - r) * (1.0 + r))) typeerror: unsupported operand type(s) -: 'float' , 'decimal' 

anybody run solution this?

as error suggests, problem arises because pearsonr function trying run arithmetic operations on float , decimal, , python doesn't that. can, however, convert decimal list floats -

stats.pearsonr([float(val) val in signals], [float(val) val in prices]) 

even though in comments mentioned want use decimal precise format, floating point errors hardly alter results.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -