首页 > 解决方案 > ValueError:使用 np.randaom.multivariate_normal 设置具有序列的数组元素

问题描述

遇到以下代码块的问题,不确定问题是什么。有人建议调试吗?

mean = [0,0,0]
df_shape = df_arr.shape[0]
cov = [[.01/1525,0,0],[0,.01/2740,0],[0,0,.01/maxZ]]
draw = np.random.multivariate_normal(mean, cov, df_shape)
df_arr+draw

追溯细节:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.6/site-packages/pandas/core/series.py in wrapper(self)
    111             return converter(self.iloc[0])
--> 112         raise TypeError(f"cannot convert the series to {converter}")
    113 

TypeError: cannot convert the series to <class 'float'>

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-7-06eeed8242a3> in <module>
      2 df_shape = df_arr.shape[0]
      3 cov = [[.01/1525,0,0],[0,.01/2740,0],[0,0,.01/maxZ]]
----> 4 draw = np.random.multivariate_normal(mean, cov, df_shape)
      5 df_arr+draw

mtrand.pyx in numpy.random.mtrand.RandomState.multivariate_normal()

ValueError: setting an array element with a sequence.

标签: pythonnp

解决方案


推荐阅读