range, xrange, arange, linspace的
1. range
-
range([start,] stop[, step])
:
创建一个整数列表(list),一般用在 for循环中,其中的参数只能为整数
2. arange
-
numpy.arange([start, ]stop, [step, ]dtype=None)
:
返回一个包括start
,但不包括stop
,间隔为step
的数组(ndarray),其中的参数可以为小数;当参数是整数时等价于 python 自带的 range
3. linspace
-
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
:
其中 endpoint
缺省为 True
表示默认包含最后一个点(stop
)
在 [start, end] 中均匀取 num 个数,返回一个数组(ndarray
)
4. xrange
-
xrange
只存在于python 2.x 版本中,在 python 2.x 版本中,对于非常长的范围,建议使用 xrange
,其参数与range
一样,但不会预先产生所有的值,而是返回一个用于逐个产生整数的迭代器;
在 python 3中,range
始终返回迭代器,因此弃用xrange
本文标题:range, xrange, arange, linspace的
本文链接:https://www.haomeiwen.com/subject/ktyxsqtx.html
网友评论