亲宝软件园·资讯

展开

python 获取等间隔的数组实例

人气:0

可以使用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 获取等间隔的数组实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

您可能感兴趣的文章:

加载全部内容

相关教程
猜你喜欢
用户评论