python - How to create a new numpy array from a calculation of elements within an existing numpyarray -


i'm python , numpy newbie...and i'm stuck. i'm trying create new numpy array log returns of elements in existing numpy array (i.e. new array = old array(with ln(x/x-1)). not using pandas dataframe because plan incorporate correlations of returns (i.e. "new array) large monte carlo simulation. open suggestions if not right path.

this closest result found in stackflow search, not working: what efficient way log returns in numpy

my guess need pass in elements of existing array thought using arrays , functions within numpy whole benefit of moving away pandas series , python base code. appreciate , feedback!

code link(i'm new stackflow won't let me embed images): http://i.stack.imgur.com/wkf56.png

numpy log function, can apply directly array. return value new array of same shape. keep in mind input should array of positive values dtype == float.

import numpy old_array = numpy.random.random(5.) * 10.  new_array = numpy.log(old_array / (old_array - 1.))  print type(old_array) # <type 'numpy.ndarray'> print old_array.dtype # float64 print old_array # [ 8.56610175  6.40508542  2.00956942  3.33666968  8.90183905] print new_array # [ 0.12413478  0.16975202  0.68839656  0.35624651  0.11916237] 

Comments

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -