您的位置:首页 > 编程语言 > Python开发

python 获取等间隔的数组实例

2019-07-04 11:43 1001 查看

可以使用numpy中的linspace函数

np.linspace(start, stop, num, endpoint, retstep, dtype)
#start和stop为起始和终止位置,均为标量
#num为包括start和stop的间隔点总数,默认为50
#endpoint为bool值,为False时将会去掉最后一个点计算间隔
#restep为bool值,为True时会同时返回数据列表和间隔值
#dtype默认为输入变量的类型,给定类型后将会把生成的数组类型转为目标类型
np.linspace(1,3,num=4)
Out[17]: array([1.    , 1.66666667, 2.33333333, 3.    ])

np.linspace(1,3,num=4,endpoint=False)
Out[18]: array([1. , 1.5, 2. , 2.5])

np.linspace(1,3,num=4,endpoint=False,retstep=True)
Out[19]: (array([1. , 1.5, 2. , 2.5]), 0.5)

np.linspace(1,3,num=4,endpoint=False,retstep=True,dtype=float)
Out[20]: (array([1. , 1.5, 2. , 2.5]), 0.5)

np.linspace(1,3,num=4,endpoint=False,retstep=True,dtype=int)
Out[21]: (array([1, 1, 2, 2]), 0.5)

以上这篇python 获取等间隔的数组实例就是小编分享给大家的全部内容了,希望能给大家一个参考

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 等间隔 数组