arange函数--Numpy

arange函数–Numpy

函数功能:
Return evenly spaced values within a given interval.
依据给定区间,返回间隔均匀的值
Values are generated within the half-open interval [start, stop) (in other words, the interval including start but excluding stop). For integer arguments the function is equivalent to the Python built-in range function, but returns an ndarray rather than a list.
数值产生于半开区间[start,stop),即包含起始值,但不包含终止值。对于整数参数,函数的功能相当于range()函数,只是返回的时一个数组而非列表。
When using a non-integer step, such as 0.1, the results will often not be consistent. It is better to use numpy.linspace for these cases.
当使用非整数步长时,例如0.1的步长,通常会产生不连续的结果,此时使用linspace函数更合适。
函数语法:
arange([start, ]stop, [step, ]dtype=None)

函数参数:
start: number, optional
Start of interval. The interval includes this value. The default start value is 0.
起始值:可选参数,数值型
区间的起始值,包含起始值,默认起始值为0.

stop: number
End of interval. The interval does not include this value, except in some cases where step is not an integer and floating point round-off affects the length of out.
结束值:数值型
区间的结束值,不包含结束值,特殊情况:步长为非整数且浮点舍入影响了输出的长度。
step: number, optional
Spacing between values. For any output out, this is the distance between two adjacent values, out[i+1] - out[i]. The default step size is 1. If step is specified as a position argument, start must also be given.
步长:数值型,可选参数,
产生的数值之间的间隔。输出结果中,两个相邻值之间的距离。默认步长为1,若步长指定需同时指定起始值。
dtype: dtype
The type of the output array. If dtype is not given, infer the data type from the other input arguments.
输出数组的类型。若参数 d b y t e dbyte dbyte没有给出,通过输入参数推断输出数据类型。

import numpy as np
# 只有stop值,默认start=0,step=1
a = np.arange(5)
print(a)
'''
#若指定步长需同时指定起始值,
# 否则,程序会将两个值分别作为起始值与终止值,没有值产生,输出空列表
'''
b = np.arange(5, 2)
print(b)

# 指定步长step=2
c = np.arange(0, 5, 2)
print(c)

# 指定步长step=0.5
d = np.arange(0, 5, 0.5)
print(d)

产生结果如下:
在这里插入图片描述
官方文档arange()函数

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值