本篇博客介绍np.linspace用法
np.linspace用来建立等差数据
用法:
np.linspace(start,end, num, endpoint=True)
参数含义:
start:开始的点
end: 结束的点
num: 数列中点的个数
endpoint:是否包含end,默认为True(包含)
即:当endpoint = True时, interval = (end-start) / (num-1)
当endpoint = False时,interval = (end-start) / num
实例
import numpy as np
import pandas as pd
x = np.linspace(1,4,endpoint=True, num=5)
x
'''
array([1. , 1.75, 2.5 , 3.25, 4. ])
'''
import numpy as np
import pandas as pd
y = np.linspace(1,4,endpoint=False, num=5)
y
'''
array([1. , 1.6, 2.2, 2.8, 3.4])
'''