python基础之numpy.linspace

numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)

在指定的间隔内返回均匀间隔的数字。

返回num均匀分布的样本,在[start, stop]。

这个区间的端点可以任意的被排除在外。

参数解释:

start : scalar(标量)

The starting value of the sequence(序列的起始点).

stop : scalar

序列的结束点,除非endpoint被设置为False,在这种情况下, the sequence consists of all but the last of num + 1 evenly spaced samples(该序列包括所有除了最后的num+1上均匀分布的样本(感觉这样翻译有点坑)), 以致于stop被排除.当endpoint is False的时候注意步长的大小(下面有例子).

num : int, optional(可选)

生成的样本数,默认是50。必须是非负。

endpoint : bool, optional

如果是真,则一定包括stop,如果为False,一定不会有stop

retstep : bool, optional

If True, return (samples, step), where step is the spacing between samples.(看例子)

dtype : dtype, optional

The type of the output array. If dtype is not given, infer the data type from the other input arguments(推断这个输入用例从其他的输入中).

官网的例子

Examples

>>>

>>> 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)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,229评论 0 13
  • 基础篇NumPy的主要对象是同种元素的多维数组。这是一个所有的元素都是一种类型、通过一个正整数元组索引的元素表格(...
    oyan99阅读 10,579评论 0 18
  • # NumPy ## The Basics NumPy 主要面向的对象是齐次多维数组。在NumPy中维度(dime...
    昨年今日阅读 2,299评论 0 1
  • 介绍 NumPy 是一个 Python 包。 它代表 “Numeric Python”。 它是一个由多维数组对象和...
    喔蕾喔蕾喔蕾蕾蕾阅读 5,770评论 0 5
  • 爸爸说今天要给我安an装学习桌,开心吗?。我说:嗯en!太开心啦,因in为我在也不用爬在板凳上温un习功课课。我都...
    段智耀阅读 1,427评论 0 0

友情链接更多精彩内容