大佬教程收集整理的这篇文章主要介绍了np.linspace,numpy中的linspace(,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import numpy as np
x=np.linspace(1,10)
y=np.linspace(1,10,num=10,retstep=TruE)
print(X)
print (y)
由结果可得,一般linspace生成含有50个数的等间隔数列,前两个参数是数列开始和结尾,第三个是数列中元素个数。retstep输出一个元组,元组的分别是生成的数列和数列的等间隔数值。
np.linspace主要用来创建等差数列。
numpy.linspace(start, stop, num=50, endpoint=True, retstep=false, dtype=None, axis=0)Return evenly spaced numbers over a specified interval.(在start和stop之间返回均匀间隔的数据)Returns num evenly spaced samples, calculated over thE interval [start, stop].(返回的是 [start, stop]之间的均匀分布)The endpoint of thE interval can optionally be excluded.Changed in version 1.16.0: Non-scalar start and stop are now supported.(可以选择是否排除间隔的终点)
参数含义:
start:队列的开始值
stop:队列的结束值。当'endpoint = false'时,不包含该点。
num:要生成的样本数。默认是50。
endpoint(bool型):如果是true,'stop'是最后样本。否则不包含'stop'。
retstep(bool型):如果是true,返回('samples', 'step')
返回值:
samples(ndarray型):闭区间[start, stop]或者是半开区间[start, stop)中有num个等间距样本。
step(float型):仅当'retstep = True'时返回。样本间距大小
start:返回样本数据开始点stop:返回样本数据结束点num:生成的样本数据量,默认为50endpoint:True则包含stop;false则不包含stopretstep:If True, return (samples, step), where step is the spacing between samples.(即如果为True则结果会给出数据间隔)dtype:输出数组类型axis:0(默认)或-1
示例:
>>> np.linspace(2.0, 3.0, num=5)array([ 2. , 2.25, 2.5 , 2.75, 3. ])>>> np.linspace(2.0, 3.0, num=5, endpoint=falsE)array([ 2. , 2.2, 2.4, 2.6, 2.8])>>> np.linspace(2.0, 3.0, num=5, retstep=TruE)(array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)原文链接:https://blog.csdn.net/Asher117/article/details/87855493
以上是大佬教程为你收集整理的np.linspace,numpy中的linspace(全部内容,希望文章能够帮你解决np.linspace,numpy中的linspace(所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。