Index entire array backwards in for loop

前端 未结 2 1016
时光取名叫无心
时光取名叫无心 2021-01-18 19:58

Suppose I would like to loop over an array and within the loop index the array forward and backward for all of its indices like so:

x = np.random.uniform(siz         


        
2条回答
  •  有刺的猬
    2021-01-18 20:13

    Why don't you just use the length information:

    length = len(x)
    
    for i in range(length):
        dot = np.dot(x[:length-i], x[i:])
    

提交回复
热议问题