0
slice() object in Python
import numpy as np letters = np.array([1, 3, 5, 7, 9, 7, 5]) print(letters[0:5:2]) print(letters[slice(letters[0,5,2])]) OUTPUT: [1 5 9] ( IndexError: too many indices for array) Why is this error coming ? I have seen on internet that both these notations works similarly.
1 Resposta
+ 3
print(letters[slice(0, 5, 2)])
or
s = slice(0, 5, 2)
print(letters[s])