Python中numpy库的linspace函数

inspace(start, stop, num=[], endpoint=True, retstep=False, dtype=None)

在指定的间隔范围内返回均匀间隔的数字。在[start, stop]范围内计算,返回num个(默认为50)均匀间隔的样本。

参数
1、start [scalar] 返回序列的初始值。
2、stop [scalar] 除非endpoint被设置为False,否则stop为序列的终点值。值得注意的是,当endpoint=False时,返回序列的步长会发生变化。
3、num [int, optional] 产生的样本总数。默认值为50。必须为非负值。
4、endpoint [bool, optional] 若为True,则stop为最后一个样本。否则,返回序列不包含stop。默认值为True。
5、retstep [bool, optional] 若为True,返回(samples, step),step为样本间的步长。
6、dtype [dtype, optional] 返回序列的数据类型。如果dtype未给定,那么从其他输入参数推断其类型。

import numpy as np

A = np.linspace(1, 10)
print(A)

B = np.linspace(1, 10, num = 10)
print(B)

C = np.linspace(1, 10, num = 10, endpoint=False)
print(C)

D = np.linspace(1, 10, num = 10, endpoint=False, retstep=True)
print(D)

E = np.linspace(1, 10, num = 10, retstep=True)
print(E)

'''
输出
[ 1.          1.18367347  1.36734694  1.55102041  1.73469388  1.91836735
  2.10204082  2.28571429  2.46938776  2.65306122  2.83673469  3.02040816
  3.20408163  3.3877551   3.57142857  3.75510204  3.93877551  4.12244898
  4.30612245  4.48979592  4.67346939  4.85714286  5.04081633  5.2244898
  5.40816327  5.59183673  5.7755102   5.95918367  6.14285714  6.32653061
  6.51020408  6.69387755  6.87755102  7.06122449  7.24489796  7.42857143
  7.6122449   7.79591837  7.97959184  8.16326531  8.34693878  8.53061224
  8.71428571  8.89795918  9.08163265  9.26530612  9.44897959  9.63265306
  9.81632653 10.        ]
[ 1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]
[1.  1.9 2.8 3.7 4.6 5.5 6.4 7.3 8.2 9.1]
(array([1. , 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1]), 0.9)
(array([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.]), 1.0)
’‘’

你可能感兴趣的:(Python)