0

I have a very quick question about the notation on accessing an array in python.

Is this line:

trainPredictPlot[look_back:len(trainPredict) + look_back, :] = trainPredict

I've seen arrays are being accessed like this x[a:b] but never like this x[a:b,:]

Can someone explain me with detail what this line of code is doing? What does it mean to put colon before the closing bracket? What about the comma?

1

1 Answer 1

2

When you use x[a:b], it means that you are taking the elements from position "a" (x[a]) to position "b" (x[b]) of a one dimensional array. For the second case x[a:b,:], it is a two dimensional "a" to position "b" of the first dimension of the array, and all the elements of the second dimension of the array, in other words, from x[a][first element] to x[b][last element].

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. Expanding on that notation then is it possible to add as many comas as dimensions my array has?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.