numpy.linspace

Scipy.org -> Docs -> NumPy v1.15 Manual -> NumPy Reference -> Routines -> Array creation routines

numpy.linspace

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

Return evenly spaced numbers over a specified interval.
Returns num evenly spaced samples, calculated over the interval [start, stop].
The endpoint of the interval can optionally be excluded.
(即,返回指定区间[start,stop]内,均匀间隔的数值。num表示一共要获得多少数字。endpoint表示所得数字是否包含端点stop,默认包含。retstep表示是否给出数字之间的间隔值。dtype为数字的类型。)

Parameters:

  • start : scalar
    The starting value of the sequence.
  • stop : scalar
    The end value of the sequence, unless endpoint is set to False. In that case, the sequence consists of all but the last of num + 1 evenly spaced samples, so that stop is excluded. Note that the step size changes when endpoint is False.
  • num : int, optional
    Number of samples to generate. Default is 50. Must be non-negative.
  • endpoint : bool, optional
    If True, stop is the last sample. Otherwise, it is not included. Default is True.
  • retstep : bool, optional
    If True, return (samples, step), where step is the spacing between samples.(retstep为true的话,返回值中,除了给出一系列样本点(samples),还会给出样本点之间的间隔大小step。)
  • dtype : dtype, optional
    The type of the output array. If dtype is not given, infer the data type from the other input arguments.

New in version 1.9.0.

Returns:

  • samples : ndarray
    There are num equally spaced samples in the closed interval [start, stop] or the half-open interval [start, stop) (depending on whether endpoint is True or False).
  • step : float, optional
    Only returned if retstep is True
    Size of spacing between samples.

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) # 每两个样本点之间间隔0.25。
(array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ]), 0.25)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,448评论 0 10
  • 如今,《王者荣耀》已俨然成为当下年轻人中最流行的一款游戏,在闲暇之余很多人都想打上一把来消遣时光。可笔者在此款游戏...
    折口怪言阅读 350评论 1 1
  • 岁月是无情的 不经意间就溜走 岁月是有情的 给我们以成长、收获 她永远是最杰出的的画师 你懈怠、你勤奋 你背离、你...
    长安秋叶阅读 205评论 0 0
  • 第一天,有人鼓励、赞赏…… 第二天,有人不屑、嘲讽…… 第三天,………. 第十一天,有人说我装逼,有人说我天天撒鸡...
    小黄毛学长阅读 342评论 0 0