【发布时间】:2021-12-11 08:06:09
【问题描述】:
有人能解释一下为什么下面的第二个断言失败了吗?我不明白为什么在这种情况下使用切片或范围进行索引会有所不同。
import numpy as np
d = np.zeros(shape = (1,2,3))
assert d[:, 0, slice(0,2)].shape == d[:, 0, range(0,2)].shape #This doesn't trigger an exception as both operands return (1,2)
assert d[0, :, slice(0,2)].shape == d[0, :, range(0,2)].shape #This does because (1,2) != (2,1)...
【问题讨论】: