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.

6th Jun 2019, 9:08 PM
harshit
harshit - avatar
1 Resposta
+ 3
print(letters[slice(0, 5, 2)]) or s = slice(0, 5, 2) print(letters[s])
6th Jun 2019, 9:24 PM
Anna
Anna - avatar