SyntaxError:无法分配给函数调用(For循环) [英] SyntaxError: can't assign to function call (For Loop)

查看:148
本文介绍了SyntaxError:无法分配给函数调用(For循环)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从先前的阵列创建一个新的阵列.这样,在新数组中,第一个元素是现有数组中前20个元素的均值.这是我的代码.我不确定为什么它不起作用.

Hi I am trying to create a new array from a previous array. such that in new array the first element is mean of first 20 elements from existing array. Here is my code. I am not sure why its not working.

#Averages
RPMA=[]
for i in range(9580):
  for j in range (0,191600):
    a=RPM.iloc[j:j+20]
    RPMA(i)= a.mean()

推荐答案

在我看来,您使用的括号类型错误.这行:

Looks to me like you're using the wrong kind of brackets. This line:

RPMA(i)= a.mean()

...可能应该是这样:

...should probably be this:

RPMA[i]= a.mean()

但是我不是Python专家.我猜想它认为RPMA(i)是一个函数,因为您使用括号,在这种情况下,您将试图为函数调用分配一个值,如错误所示.

But I'm no Python expert. I guessing that it thinks RPMA(i) is a function because you use parentheses, in which case you would be trying to assign a value to a function call, like the error says.

但是,尝试在数组末尾分配新值将导致IndexError,因为该数组元素不存在,需要添加.您可以做的是这样:

However trying to assign a new value past the end of the array will result in an IndexError because the array element doesn't exist, and will need to be added. What you can do instead is this:

RPMA.append(a.mean())

...这会将数据附加到数组的末尾(即添加一个新元素).

...which will append the data to the end of the array (i.e. adding a new element).

这篇关于SyntaxError:无法分配给函数调用(For循环)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆