Created
March 5, 2012 09:55
-
-
Save npinto/1977686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from numpy.lib.stride_tricks import as_strided | |
| for dtype in ('float32', 'float16'): | |
| print 'trying with', dtype | |
| arr_in = np.random.randn(10, 10, 4).astype(dtype) | |
| window_shape = (5, 5, 1) | |
| arr_shape = np.array(arr_in.shape) | |
| window_shape = np.array(window_shape, dtype=arr_shape.dtype) | |
| arr_in = np.ascontiguousarray(arr_in) | |
| new_shape = tuple(arr_shape - window_shape + 1) + tuple(window_shape) | |
| new_strides = arr_in.strides + arr_in.strides | |
| arr_out = as_strided(arr_in, shape=new_shape, strides=new_strides) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment