how to cut a python list code example
Example 1: python slice an array
a[start:stop] # items start through stop-1
a[start:] # items start through the rest of the array
a[:stop] # items from the beginning through stop-1
a[:] # a copy of the whole array
Example:
>>> a = [1, 2, 3, 4, 5, 6, 7, 8]
>>> a[1:4]
[2, 3, 4]
Example 2: python slice second element of list of lists
import numpy as np
A = np.array([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]])
A[:,:3]
Out[3]:
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])