Using Python Slice Objects to Index a ndarray

Some times you just want to use an object(variable) to refering to those : functionalities in your python code, you can achieve this by:

slice(none) # the same as [:]
slice(start, stop) # the same as [start:stop]
slice(none, stop)  # [:stop]
slice(start, none) # [start:]
slice(start, stop, step) # [start:stop:step]

Have fun :)

Previous topic

Python Cheatsheet

Next topic

使用 Virtualenv 与 pip 进行科学计算库开发

This Page