python - How to resample a Numpy array of arbitrary dimensions? -


there scipy.misc.imresize resampling first 2 dimensions of 3d arrays. supports bilinear interpolation. however, there not seem existing function resizing dimensions of arrays number of dimensions. how can resample array given new shape of same rank, using multi-linear interpolation?

you want scipy.ndimage.zoom, can used follows:

>>> x = np.arange(8, dtype=np.float_).reshape(2, 2, 2) >>> scipy.ndimage.zoom(x, 1.5, order=1) array([[[ 0. ,  0.5,  1. ],         [ 1. ,  1.5,  2. ],         [ 2. ,  2.5,  3. ]],         [[ 2. ,  2.5,  3. ],         [ 3. ,  3.5,  4. ],         [ 4. ,  4.5,  5. ]],         [[ 4. ,  4.5,  5. ],         [ 5. ,  5.5,  6. ],         [ 6. ,  6.5,  7. ]]]) 

note function preserves boundaries of image, resampling mesh node @ each pixel center. might want @ other functions in scipy.ndimage if need more control on resampling occurs


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -