Slicing
Arrays can be sliced just like lists and tuples. Array slicing is identical to list slicing, except that the syntax is simpler. Arrays are sliced using the [ : , :, ... :]
syntax, where the number of dimensions of the arrays determine the size of the slice, except that these dimensions for which slices are omitted, all elements are selected. For example, if b
is a three-dimensional array, b[0:2]
is the same as b[0:2,:,:]
. There are shorthand notations for slicing. Some common ones are:
- : and: are the same as 0:n:1, where n is the length of the array
- m: and m:n: are the same as m:n:1, where n is the length of the array
- :n: is the same as 0:n:1
- ::d: is the same as 0:n:d, where n is the length of the array
All these slicing methods have been referenced with the usage of arrays. This can also be applicable to lists. Slicing of one-dimensional arrays is identical to slicing a simple list (as one-dimensional arrays can be seen equivalent to a list), and the returned type of all the slicing...