python numpy.linspace() 使用介绍
numpy.linspace()
在指定的间隔内返回均匀间隔的数字。
示例
1)
# -*- coding: utf-8 -*-
"""
@File : test.py
@Time : 2020/4/1 19:24
@Author : Dontla
@Email : sxana@qq.com
@Software: PyCharm
"""
import numpy as np# 在闭区间[2, 3]生成5个间隔相同的数字
print(np.linspace(2.0, 3.0, num=5))
# [2. 2.25 2.5 2.75 3. ]# 在半开区间[2, 3)生成5个间隔相同的数字
print(np.linspace(2.0, 3.0, num=5, endpoint=False))
# [2. 2.2 2.4 2.6 2.8]# 在闭区间[2, 3]生成5个间隔相同的数字(除了返回生成的样本数字,还返回样本数字之间的间距)
print(np.linspace(2.0, 3.0, num=5, retstep=True))
# (array([2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)
2)
官方doc
def 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 theinterval [`start`, `stop`].The endpoint of the interval can optionally be excluded.返回指定区间内的均匀间隔的数字。返回在区间[`start`,`stop`]中计算出的num个均匀间隔的样本。区间的端点可以选择排除。Parameters----------start : scalarThe starting value of the sequence.序列的起始值。stop : scalarThe 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 stepsize changes when `endpoint` is False.序列的结束值,除非将“ endpoint”设置为False。在这种情况下,该序列由除num + 1之外的所有其他均匀间隔的样本组成,因此排除了stop。 注意,当`endpoint`为False时步长会改变。num : int, optionalNumber of samples to generate. Default is 50. Must be non-negative.要生成的样本数。 默认值为50。必须为非负数。endpoint : bool, optionalIf True, `stop` is the last sample. Otherwise, it is not included.Default is True.如果为True,则“ stop”是最后一个样本。 否则,不包括在内。默认值为True。retstep : bool, optionalIf True, return (`samples`, `step`), where `step` is the spacingbetween samples.如果为True,则返回(“ samples”,“ step”),其中“ step”是样本之间的间距。dtype : dtype, optionalThe type of the output array. If `dtype` is not given, infer the datatype from the other input arguments.输出数组的类型。 如果未给出dtype,则从其他输入参数推断数据类型。.. versionadded:: 1.9.0Returns-------samples : ndarrayThere 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).在闭区间“ [start,stop]”或半开区间“ [start,stop)”中有“ num”个等距样本(取决于“ endpoint”是True还是False)。step : float, optionalOnly returned if `retstep` is True仅在`retstep`为True时返回Size of spacing between samples.样本之间的间距大小。See Also--------arange : Similar to `linspace`, but uses a step size (instead of thenumber of samples).类似于linspace,但是使用步长(而不是样本数)。logspace : Samples uniformly distributed in log space.样本在日志空间中均匀分布。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)(array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)Graphical illustration:图形说明:>>> 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')[<matplotlib.lines.Line2D object at 0x...>]>>> plt.plot(x2, y + 0.5, 'o')[<matplotlib.lines.Line2D object at 0x...>]>>> plt.ylim([-0.5, 1])(-0.5, 1)>>> plt.show()"""
参考文章:numpy.linspace使用详解
8小时Python零基础轻松入门
python numpy.linspace() 使用介绍相关推荐
- Python – numpy.linspace()
Being a sequence generator, the numpy.linspace() function is used to generate a sequence of numbers ...
- Python Numpy介绍
Numpy简单介绍 1.Numpy是什么 很简单,Numpy是Python的一个科学计算的库,提供了矩阵运算的功能,其一般与Scipy.matplotlib一起使用.其实,list已经提供了类似于矩阵 ...
- python numpy库等差不均分_numpy.linspace 生成等差数组的方法
如下所示: numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) start:起始值 stop:结 ...
- Python中numpy.power()函数介绍
Python中numpy.power()函数介绍 power(x, y) 函数,计算 x 的 y 次方. 示例: x 和 y 为单个数字: import numpy as npprint(np.pow ...
- Python Numpy 关于 linspace()函数 使用详解(全)
目录 前言 1. 函数讲解 2. 实战讲解 前言 用plt画图的时候,偶尔会看到这个函数的出现,索性直接深入源码实战进行复现 主要功能:在线性区域中生成等间距的序列,原先在Numpy中可以用numpy ...
- python numpy 数据类型为python对象-python numPy模块 与numpy里的数据类型、数据类型对象dtype...
学习链接:http://www.runoob.com/numpy/numpy-tutorial.html 简介: numPy是python语言的一个扩展库,是一个运行非常快的数学库,主要用于数组计算. ...
- python 初始化数组 numpy,Python Numpy 数组的初始化和基本操作
Python 是一种高级的,动态的,多泛型的编程语言.Python代码很多时候看起来就像是伪代码一样,因此你可以使用很少的几行可读性很高的代码来实现一个非常强大的想法. 一.基础: Numpy的主要数 ...
- python numpy数据类型_python numPy模块 与numpy里的数据类型、数据类型对象dtype
学习链接:http://www.runoob.com/numpy/numpy-tutorial.html 简介: numPy是python语言的一个扩展库,是一个运行非常快的数学库,主要用于数组计算. ...
- [转载] python numpy 总结
参考链接: Python中的numpy.compress 先决条件 在阅读这个教程之前,你多少需要知道点python.如果你想重新回忆下,请看看Python Tutorial. 如果你想要运行教程中的 ...
最新文章
- 用子函数的方法求一维数组中所有元素之和
- Kotlin-Learning 扩展
- 用sql统计vintage,滚动率,迁移率,逾期率
- SAP CRM WebClient UI表格编辑模式的调试明细
- Linux 内核打印级别
- 项目集成Spring Security
- Mac下Git项目使用的.gitignore文件
- Java8新特性总结 -8.Nashorn , JavaScript引擎
- Qt 学习之路 :Qt 线程相关类
- amqp rabbitmq_Spring AMQP RabbitMQ示例
- 计算机与机械制图课题研究,计算机辅助技术和机械制图融合教学改革探索和实践.doc...
- kali linux网卡推荐,BT5 Kali Linux 网卡选择
- 压六类双绞线网线水晶头,
- 阿里云服务器租用测试
- python3 socket TCP 服务器 一对多转发信息
- wince车机可以连接电脑吗_WINCE车机平台手机互联使用说明
- 战术板将要下岗 iPad登陆橄榄球场
- 【C语言 基础】函数的形参与实参
- pod的requests、limits解读、LimitRange资源配额、Qos服务质量等级、资源配额管理 Resource Quotas
- 数学建模里面灵敏度分析怎么写