我在使用np.arange
时感到困惑,因为像一样只传递start
np.arange(start=3, stop=None, step=None)
array([0, 1, 2])
我在这里期待error
,因为终点没有定义。但给出的结果我想,考虑到给定的start
作为end
为什么?
实际上,我在尝试np.r_
,在像一样的切片中只通过start
np.r_[3::]
这里也一样,期望error
作为终点,但没有定义,但它将我引向np.arange
,正如doc在这里所说的
如果使用切片表示法,则语法
start:stop:step
等效于括号内的np.arange(start, stop, step)
。。。
所以我认为它类似于np.arange(start=3, stop=None, step=None)
以下是np.lib.index_tricks.AxisConcatenator
中处理解释器生成的slice
对象的部分:
if isinstance(item, slice):
step = item.step
start = item.start
stop = item.stop
if start is None:
start = 0
if step is None:
step = 1
if isinstance(step, complex):
size = int(abs(step))
newobj = linspace(start, stop, num=size)
else:
newobj = _nx.arange(start, stop, step)