numpy的linspace使用详解
2018-03-20 10:40
369 查看
文档地址:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html
第1个例子endpoint的使用:
输出:
从上面输出可以看出endpoint=True时,输出包含了“stop”这个样本点;endpoint=False时,输出不包括“stop”这个样本点;默认情况endpoint=True。
第2个例子retstep的使用:
输出:
retstep=True时输出了步长(step),此时步长为0.25
第3个例子:
输出:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html
Parameters(参数): start : 序列的起始点. stop : 序列的结束点 num : 生成的样本数,默认是50。必须是非负。 endpoint : 如果True,'stop'是最后一个样本。否则,它不包括在内。默认为True。 retstep : 如果True,返回 (`samples`, `step`) dtype :
第1个例子endpoint的使用:
import numpy as np print(np.linspace(2.0, 3.0, num=5)) print(np.linspace(2.0, 3.0, num=5, endpoint=True)) print(np.linspace(2.0, 3.0, num=5, endpoint=False))
输出:
[ 2. 2.25 2.5 2.75 3. ] [ 2. 2.25 2.5 2.75 3. ] [ 2. 2.2 2.4 2.6 2.8]
从上面输出可以看出endpoint=True时,输出包含了“stop”这个样本点;endpoint=False时,输出不包括“stop”这个样本点;默认情况endpoint=True。
第2个例子retstep的使用:
import numpy as np print(np.linspace(2.0, 3.0, num=5)) a = np.linspace(2.0, 3.0, num=5, retstep=True) print(a) print(a[0]) print(a[1])
输出:
[ 2. 2.25 2.5 2.75 3. ] (array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25) [ 2. 2.25 2.5 2.75 3. ] 0.25
retstep=True时输出了步长(step),此时步长为0.25
第3个例子:
import numpy as np import matplotlib.pyplot as plt N = 8 y = np.zeros(N) x1 = np.linspace(0, 10, N, endpoint=True) x2 = np.linspace(0, 10, N, endpoint=False) plt.plot(x1, y, 'o') plt.plot(x2, y + 0.5, 'o') plt.ylim([-0.5, 1]) plt.show()
输出:
相关文章推荐
- numpy.linspace使用详解...
- numpy.random.rand使用详解
- numpy.random.rand使用详解
- 对numpy中的where方法嵌套使用详解
- numpy.linspace使用详解
- 对python numpy数组中冒号的使用方法详解
- numpy.linspace使用详解
- Numpy 使用详解
- numpy.linspace使用详解
- 使用Log4j为项目配置日志输出应用详解以及示例演示的实现分析
- CheckStyle使用详解
- 正则表达式使用详解
- showModalDialog()、showModelessDialog()方法使用详解
- showModalDialog()、showModelessDialog()方法使用详解
- showModalDialog()、showModelessDialog()方法使用详解
- Ghost 使用详解
- SSI使用详解
- showModalDialog()、showModelessDialog()方法使用详解
- [导入]showModalDialog()、showModelessDialog()方法使用详解
- C语言使用openSSL库DES模块实现加密功能详解