1 numpy data science

 
a=[0,1,2,3,4,5] 
a[-1]    # last item in the array 
>>> a[-2]  # second last item in array it returns 4
 
a[-2:]   # last two items in the array
 
a[:-2]   # everything except the last two items
a[::-1]    # all items in the array, reversed
a[1::-1]   # the first two items, reversed
a[:-3:-1]  # the last two items, reversed
a[-3::-1]  # everything except the last two items, reversed
 
import numpy as np
array([0, 1, 2, 3, 4]) 
 
 

No comments:

Post a Comment