【发布时间】:2016-11-13 23:15:30
【问题描述】:
处理 numpy 的 sliding-window 示例。试图理解start_idx = np.arange(B[0])[:,None]的,None
foo = np.arange(10)
print foo
print foo[:]
print foo[:,]
print foo[:,None]
None 的效果似乎是对数组进行转置。
[0 1 2 3 4 5 6 7 8 9]
[0 1 2 3 4 5 6 7 8 9]
[0 1 2 3 4 5 6 7 8 9]
[[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]]
但我不完全确定。我找不到解释第二个参数 (None) 作用的文档。这也是谷歌搜索的一个难点。 numpy array docs makes me think it has something to do with advanced indexing,但我不确定。
【问题讨论】:
-
这里用作
np.newaxis的别名,用于添加单例维度(长度为1 的维度)。在示例案例中,添加它以将输入一维数组转换为2D,第二个暗淡为单例。