【Python】np.linspace用法介绍

np.linspace主要用来创建等差数列。

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:返回样本数据结束点
num:生成的样本数据量,默认为50
endpoint:True则包含stop;False则不包含stop
retstep:If True, return (samples, step), where step is the spacing between samples.(即如果为True则结果会给出数据间隔)
dtype:输出数组类型
axis:0(默认)-1

使用例子:

import numpy as np

a = np.linspace(1.0, 3.0, num=5)
print(a)
b = np.linspace(1, 3.0, num=5, endpoint=False)
print(b)
c = np.linspace(1, 3.0, num=5, retstep=True)
print(c)

输出:

[1.  1.5 2.  2.5 3. ]
[1.  1.4 1.8 2.2 2.6]
(array([1. , 1.5, 2. , 2.5, 3. ]), 0.5)
  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值