-1

I have the following input which is 2D array. And I would like to iterate over each row to do some calculation but when I print the output it seems to iterate only on the first row of the array. Any contribution would be appreciated.

2D numpy array corr_ret:

[[-6.33870149e-04  8.55011683e-04 -1.17983411e-03  7.91091491e-04
 2.62196784e-04 -4.43688931e-05 -6.45968376e-06 -1.12538630e-03
  2.15421763e-03 -3.16434832e-03  2.60707339e-03  1.50132673e-03
-1.26622898e-03 -6.60251486e-04  5.02396330e-04  2.11832581e-04
 -7.69597583e-04 -3.29756120e-03 -1.24210577e-03 -4.62660468e-04
-3.49262651e-04 -3.43464642e-04 -2.55611240e-04  5.54536845e-04
-2.01366145e-03 -2.87531971e-04 -5.34641032e-04  1.72644604e-03
 5.76858322e-04 -2.29174764e-03]
[ 4.70029370e-04  1.77020781e-03 -1.05050155e-03 -6.18841938e-04
  1.16485579e-03 -6.00092725e-05  1.05676386e-04 -1.48243613e-03
 3.72088647e-03 -1.75323439e-03  1.09075078e-03  9.89241541e-05
 -1.59512783e-03 -7.11380812e-04  1.73537083e-03  8.78393781e-04
 -9.29723278e-04 -1.53385019e-03  1.20444451e-04 -4.84107094e-04
 -7.83347205e-04  1.18777621e-03 -1.54999170e-03  8.35286745e-05
 -1.74472610e-03  9.83476064e-04 -8.82693488e-04  1.58099698e-03
  3.15406396e-03 -1.26301009e-04]
  [-1.06896577e-03  8.31379672e-04  1.54808513e-04 -1.35452237e-03
 -2.19101603e-04 -7.26696656e-04 -2.93275089e-04 -6.88305530e-04
  2.89300411e-03 -2.38832429e-03 -7.67452518e-04 -2.40866147e-04
 -2.11929402e-03 -7.45901508e-04  5.02921628e-04  1.77651468e-04
 -2.08574762e-03 -1.80218000e-03 -1.23287491e-03 -7.47521806e-04
  -7.80485878e-04  6.15345860e-04 -1.40945995e-03  8.74548883e-04
-2.78711058e-03  1.92856732e-03  5.73070388e-04  1.29301575e-03
  1.89158005e-03  8.65315240e-04]]

My code:

for row in corr_ret:
  seed = 1
  So = corr_ret[0] #the first cell of the row
  N = 30                           
  mu = corr_ret.mean()/N        
  sigma = corr_ret.std()   
  print(sigma)
  T = 1          

My output:

 [-6.33870149e-04  8.55011683e-04 -1.17983411e-03  7.91091491e-04
 2.62196784e-04 -4.43688931e-05 -6.45968376e-06 -1.12538630e-03
 2.15421763e-03 -3.16434832e-03  2.60707339e-03  1.50132673e-03
 -1.26622898e-03 -6.60251486e-04  5.02396330e-04  2.11832581e-04
-7.69597583e-04 -3.29756120e-03 -1.24210577e-03 -4.62660468e-04
-3.49262651e-04 -3.43464642e-04 -2.55611240e-04  5.54536845e-04
 -2.01366145e-03 -2.87531971e-04 -5.34641032e-04  1.72644604e-03
  5.76858322e-04 -2.29174764e-03]
-5.2605086588854405e-06
0.0013733187643799106
[-6.33870149e-04  8.55011683e-04 -1.17983411e-03  7.91091491e-04
 2.62196784e-04 -4.43688931e-05 -6.45968376e-06 -1.12538630e-03
  2.15421763e-03 -3.16434832e-03  2.60707339e-03  1.50132673e-03
 -1.26622898e-03 -6.60251486e-04  5.02396330e-04  2.11832581e-04
  -7.69597583e-04 -3.29756120e-03 -1.24210577e-03 -4.62660468e-04
 -3.49262651e-04 -3.43464642e-04 -2.55611240e-04  5.54536845e-04
 -2.01366145e-03 -2.87531971e-04 -5.34641032e-04  1.72644604e-03
 5.76858322e-04 -2.29174764e-03]
-5.2605086588854405e-06
 0.0013733187643799106
[-6.33870149e-04  8.55011683e-04 -1.17983411e-03  7.91091491e-04
 2.62196784e-04 -4.43688931e-05 -6.45968376e-06 -1.12538630e-03
 2.15421763e-03 -3.16434832e-03  2.60707339e-03  1.50132673e-03
 -1.26622898e-03 -6.60251486e-04  5.02396330e-04  2.11832581e-04
 -7.69597583e-04 -3.29756120e-03 -1.24210577e-03 -4.62660468e-04
 -3.49262651e-04 -3.43464642e-04 -2.55611240e-04  5.54536845e-04
 -2.01366145e-03 -2.87531971e-04 -5.34641032e-04  1.72644604e-03
 5.76858322e-04 -2.29174764e-03]
-5.2605086588854405e-06
0.0013733187643799106
mama dede
  • 360
  • 1
  • 12

1 Answers1

0

To get the first cell you are using the corr_ret array, (the original array) which actually returns the first row of of the array. To get the first element of each row, use So = row[0]

for row in corr_ret:
    seed = 1
    So = row[0] #the first cell of the row
    N = 30                           
    mu = corr_ret.mean()/N        
    sigma = corr_ret.std()   
    print(sigma)
    T = 1