ValueError: record "axis" out of bounds // numpy

Here is my numpy 2D array:

returns = np.array([
 [ -4.78878057e-03   9.79090927e-03  -2.06883581e-03  -1.25786164e-02]
 [  5.79128440e-03  -2.85791008e-03   1.69555388e-03  -5.63798220e-02]
 [  5.73427375e-05   2.45043133e-02   8.55025651e-03  -4.53257790e-02]
 [  6.75441635e-03   8.70168484e-03   1.07547532e-02  -1.36919315e-01]
 [  6.68332655e-03   6.76498174e-03   3.08225775e-03   0.00000000e+00]])

And when I try to calculate the STD for each column:

print np.std(returns, axis=1)

I get the following error:

ValueError: 'axis' entry is out of bounds

How can i fix this?

+4
source share
3 answers

Check if your array is a two dimensional array requesting a.ndim. It may happen that you have a 1-D array of objects that when printed looks like a 2-dimensional array. In this case, you can convert it to a 2-dimensional array:

a = np.array(list(a))

or

a = np.array(tuple(a))
+4
source

Michael

, . , , 2D- ( ). , :

import numpy as np

arr = np.array([                                                                \
[ -4.78878057e-03,   9.79090927e-03,  -2.06883581e-03,  -1.25786164e-02],       \
[  5.79128440e-03,  -2.85791008e-03,   1.69555388e-03,  -5.63798220e-02],       \
[  5.73427375e-05,   2.45043133e-02,   8.55025651e-03,  -4.53257790e-02],       \
[  6.75441635e-03,   8.70168484e-03,   1.07547532e-02,  -1.36919315e-01],       \
[  6.68332655e-03,   6.76498174e-03,   3.08225775e-03,   0.00000000e+00]        \
])

std = np.std(arr,axis=1)
print std

:

[ 0.00803178  0.02526721  0.02593599  0.06308687  0.00281146]
0

:

np.sum(myndarray, axis=0)

"ValueError:" " " , script. , IPython ( , myndarray ).

Spyder, , , - Python + pdb / IPython + ipdb . IDE , .

0

All Articles