Python:索引太多了

时间:2014-11-19 18:54:27

标签: python arrays numpy scipy indices

我正在尝试从给定条件的数组中选择数量,并拒绝其他不适合的数量。标准是:如果金额[i,:]> x *金额[i-1,:]保留,否则保留先前金额。就像一个门槛基本上。我将在新阵列Array1中填充所有这些数量。最后,曲线数组全部采用并绘制曲线。现在,无论我输入什么阈值,曲线总会给我相同的曲线。这让我认为我的Array1代码有问题。

我使用where函数填充此数组: amount是一个2 dim数组,它接受第一个索引中的日期和第二个索引中的数量。我将Array1的大小调整为相同的大小和形状。

x=2
def (i,curve):
    Array1 = zeros(shape=(amount.shape[0],amount.shape[1]))

    Array1 = where(amount[i,:]>x*Array1[i-1,:],amount[i,:],where(amount[i,:]*x<Array1[i-1,:],amount[i,:],Array1[i-1,:]))

    #this function below just takes in Array1 and gives a curve.
    curve[:] = Array1[i,:]-Array1[i-1,:]

现在,当我运行它时,我收到“索引太多”错误。有人在乎帮忙吗?如何在不指定索引的情况下获取Array1的元素?我现在已经待了2天了。

这基本上是我试图用循环做的,但这很慢,这就是我使用where函数的原因。

def curve(i, curve):
  Array1 = zeros(shape=(amount.shape[0],amount.shape[1])) 
  for u in xrange(5000):
   for i in xrange(5000):
    if amount[i,u] > 1.031*amount[i-1,u]:
      Array1[i]=amount[i,u]  
    else:
      Array1[i]=Array1[i-1,u] 

      curve[:] =Array1[i,u]-Array1[i-1,u]

0 个答案:

没有答案
相关问题