1
Oops, coming back with the column question before the variable. Example I’m seeing in python in neural recurring.
arr = arr[:n_batches * batches_size]
what the :n_batches
?
1
Oops, coming back with the column question before the variable. Example I’m seeing in python in neural recurring.
arr = arr[:n_batches * batches_size]
what the :n_batches
?
1
It’s called Slice. With it you can access a slice of an object that is eternal. For example, do lista[1:5]
you would be accessing items 1 to 4 (the 5 represents the first index not included in the slice). When omitted the first value, the slice from the beginning of the iterator will be considered. That is, do lista[:5]
is the equivalent of lista[0:5]
. If the second value is omitted, it will be considered until the end of the second value. That is, do lista[5:]
would take all values from index 5 to the end. If both numbers are omitted, you will take the iterator from start to finish, making an Raza copy of your object.
In your case,
arr = arr[:n_batches * batches_size]
You are accessing the eternal arr
from start to multiplication result n_batches * batches_size
. The equivalent would be:
arr = arr[0:n_batches * batches_size]
See some other examples:
lista = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(lista[1:5]) # [1, 2, 3, 4]
print(lista[:5]) # [0, 1, 2, 3, 4]
print(lista[1:]) # [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(lista[:]) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
And the star *
would be a normal multiplication?
@Jeffersonquesado yes, basically picking from the beginning until the result of multiplication.
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
Welcome to Stackoverflow. Please detail your question as it is very generic
– Tiedt Tech
That one
:var
is calledslice
, a special vector operation. Further information on this question (and its links and answers): https://answall.com/q/265588/64969– Jefferson Quesado