Python技术迷

NumPy教程-numpy.linspace()

整理:python架构师

它与 arange 函数类似。然而,在语法中它不允许我们指定步长。

相反,它只返回在指定区间内均匀分隔的值。系统会隐式地计算步长。

语法

numpy.linspace(start, stop, num, endpoint, retstep, dtype)

参数

它接受以下参数。

  1. start:表示区间的起始值。

  2. stop:表示区间的结束值。

  3. num:要生成的区间内均匀间隔样本的数量。默认为 50。

  4. endpoint:它的真值表示区间中包含结束值。

  5. retstep:这必须是一个布尔值。表示连续数字之间的步长和样本。

  6. dtype:表示数组项的数据类型。

返回值

返回在指定范围内的数组。

示例 1

import numpy as np  arr = np.linspace(10, 20, 5)  print("The array over the given range is ",arr)
输出:
The array over the given range is  [10.  12.5 15.  17.5 20.]

专属福利 

👉点击领取:最全Python资料合集

示例 2

import numpy as np  arr = np.linspace(10, 20, 5, endpoint = False)  print("The array over the given range is ",arr)
输出:
The array over the given range is  [10. 12. 14. 16. 18.]
Image
 1
Image
热门推荐
Image