简体   繁体   English

Python 索引错误:数组的索引太多

[英]Python index error: too many indices for array

I am trying to code a plot with this code:我正在尝试使用以下代码对 plot 进行编码:

         for k in range(5):   
            plt.scatter(np.arange(0,200),cprofit[:,k],label = marketshare)
         a = pd.Series([np.mean(cprofit[:,k]), np.std(cprofit[:,k]), np.max(cprofit[:,k]), np.min(cprofit[:,k])], index=df.columns)
         df = df.append(a,ignore_index=True)

The error:错误:

a = pd.Series([np.mean(cprofit[:,k]), np.std(cprofit[:,k]), np.max(cpro fit[:,k]), np.min(cprofit[:,k])], index=df.columns)

IndexError: too many indices for array: array is 1-dimensional,  but 2 were indexed

for line对于线

can someone explain what could be wrong??有人可以解释什么可能是错的吗?

The two inputs of plt.scatter() should be of the same dimension, and size. plt.scatter()的两个输入应该具有相同的维度和大小。 You have numpy.arange(0, 200) creating a 1-dimensional array of size 200, and it's unclear what cprofit[:,k] is doing, but it seems to be slicing a large 2-D array, which may or may not produce a 1-D array of size 200.您有numpy.arange(0, 200)创建一个大小为 200 的一维数组,目前尚不清楚cprofit[:,k]在做什么,但它似乎正在切片一个大的二维数组,这可能会或可能不会生成大小为 200 的一维数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM