Using Numpy stride_tricks to get non-overlapping array blocks

后端 未结 3 1310
执念已碎
执念已碎 2020-11-29 09:39

I\'m trying to using numpy.lib.stride_tricks.as_strided to iterate over non-overlapping blocks of an array, but I\'m having trouble finding documentation of the parameters,

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 10:08

    scikit-image has a function named view_as_blocks() that does almost what you need. The only problem is that it has an extra assert that forbids your use case, since your blocks don't divide evenly into your array shape. But in your case, the assert isn't necessary, so you can copy the function source code and safely remove the pesky assert yourself.

提交回复
热议问题