Is it possible to use numpy.split
to split a numpy.ndarray with overlapping pieces.
Example:
Given a numpy.ndarray of shape (3,3) and I want to split it into ndarray, of shape (1,1) which by
numpy.split((3,3),(1,1)) = [(1,1),(1,1),(1,1)]
But what if i wanted numpy.ndarrays of shape (3,2) , would it be able to generate a list with length 2 with overlapping numpy.ndarrays?
as such:
答案 0 :(得分:1)
I am not exactly sure what you want to see, but this might answer your question:
With input:
> arr = np.arange(9, dtype='int64').reshape((3, 3))
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
> np.lib.index_tricks.as_strided(arr, (2, 2, 2, 2), (24, 8, 24, 8), True)
array([[[[0, 1],
[3, 4]],
[[1, 2],
[4, 5]]],
[[[3, 4],
[6, 7]],
[[4, 5],
[7, 8]]]])
Interestingly, there are no copies of the data here. Note that the values to as_strided
are only accurate for 8-byte values and a 3x3 input. You could get them from the existing shape/strides of the input.