How should I handle inclusive ranges in Python?

后端 未结 12 2231
天涯浪人
天涯浪人 2020-12-14 05:56

I am working in a domain in which ranges are conventionally described inclusively. I have human-readable descriptions such as from A to B , which represent rang

12条回答
  •  情歌与酒
    2020-12-14 06:04

    If you don't want to specify the step size but rather the number of steps, there is the option to use numpy.linspace which includes the starting and ending point

    import numpy as np
    
    np.linspace(0,5,4)
    # array([ 0.        ,  1.66666667,  3.33333333,  5.        ])
    

提交回复
热议问题