Prange loop with a call for i+1

I have following code:

@numba.njit(parallel=True)
def func(n):
A=np.zeros(n)
for i in numba.prange(n):
A[i:i+1] += 2*i
return A

This throws an error because of the i+1, but I need the part of A to be a slice, not an element. What is the way to do this?

hi @Hanni-ui , I don’t know why your version does not wori, but you can use a loop instead of a slice, and it will work. Numba works very well with loops, it’s not necessary to vectorize operations to obtain performance.

@njit(parallel=True)
def func(n):
    A=np.zeros(n)
    for i in numba.prange(n):
        for j in range(1):
            A[i+j] += 2*i
    return A

Hi luk,
thank you very much. The problem is, that I need the references of the array. I link the array to attributes of objects, so that when I change the array, the attributes of the object will change too. So I really need to call the slice, the simple element isn’t enough.
Can you reproduce my error? I’m not very experienced with errors in numba, and it is just my assumption, that numba in parallel mode doesn’t wants to look at the i+1. argument while handling the i. argument.

I link the array to attributes of objects, so that when I change the array, the attributes of the object will change too.

I don’t understand what you mean by that. The code that I provided does the same as yours. That “link” that you speak about, can you explain how is created?

While trying to reproduce my error, I realized that some things are not problematic which I thought were problematic. So, I think, my problem is solved, thanks.