ValueError错误:'轴'条目是出界// numpy的的 [英] ValueError: 'axis' entry is out of bounds // numpy
本文介绍了ValueError错误:'轴'条目是出界// numpy的的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的2D numpy的数组:
Here is my 2D numpy 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]])
而当我试图计算STD为每列:
And when I'm trying to calculate the STD for each column:
print np.std(returns, axis=1)
我收到以下错误:
I'm getting the following error:
ValueError: 'axis' entry is out of bounds
我该如何解决呢?
How can I fix that?
推荐答案
检查您的数组是一个二维数组查询 a.ndim
。可能发生的是你有对象的一维阵列,在打印时,看起来像的2-D阵列。在这种情况下,你可以将其转换为一个二维数组做的:
Check if your array is a 2-D array querying a.ndim
. It may happen that you have a 1-D array of objects that, when printed, looks like a 2-D array. In this case you can convert it to a 2-D array doing:
a = np.array(list(a))
或
a = np.array(tuple(a))
这篇关于ValueError错误:'轴'条目是出界// numpy的的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文