根据docs,np.lib.stride_tricks.as_strided
的步长参数默认为输入的步长:
[...] The strides of the new array. Defaults to x.strides.
但是,当我执行以下操作时,步幅会发生变化:
import numpy as np
from numpy.lib.stride_tricks import as_strided
print("The following should be identical:")
foo = np.arange(100).reshape(10, 10)
print(f"Foo strides: {foo.strides}")
bar = as_strided(foo, (5, 5))
print(f"Bar strides: {bar.strides}")
产生:
The following should be identical:
Foo strides: (40, 4)
Bar strides: (20, 4)
我在python 3.7.0中使用numpy 1.19。发生了什么事,我做错了什么
这是文档和代码之间的不匹配。{a1}的开头是这样的:
因此
strides
的实际默认值是'strides'
键在x.__array_interface__
中的任何值。对于C-连续数组,该值是None
,而不是实际的步长元组,代码继续生成C-连续输出,而不是保持输入步长相关问题 更多 >
编程相关推荐