Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
877 views
in Technique[技术] by (71.8m points)

arrays - Python: Too many indices

I am trying to select amounts from an array given a criteria and reject the other amounts that do not fit. The criteria is: if amount[i,:]> x*amount[i-1,:] keep, otherwise keep prior amount. just like a treshold basically. And I am filling all these amount selected within a new array Array1. In the end the curve array takes it all and draws a curve. Now, the curve somehow always give me the same curve no matter what treshold i put in. This leads me to think that something is wrong with my Array1 code.

I am filling this array with a where function: amount is a 2 dim array taking in a date in the first index and an amount in the second index. I size up the Array1 to the same size and shape.

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,:]

Now, when I run it, I get a "too many indices" error. Anyone care to help? How can I get an element of Array1 without specifying its index? I've been at it for 2 days now.

This is basically what iam trying to do with loops, but this is very slow, this is why i use the where function.

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]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...