简体   繁体   中英

resize using fractional step in numpy

how can I modify the size of a numpy array with a non-integer step? that is: To convert a 3D array with size (64,64,64) into a 3D array for example with size (55,100,60), interpolating the values or using something like kron function

How do you want to interpolate?

There's no "best", "right", or "normal" way to interpolate data... It all depends on your problem.

There are a large number of different ways to do what you want.

A starting point would be scipy.ndimage.zoom which can use spline, linear, or nearest-neighbor interpolation, and does exactly what you want.

Specifying order=0 will give nearest-neighbor interpolation, order=1 will give linear interpolation, and anything greater than 1 will give the specified order of spline interpolation. (The default is order=3 , which is "cubic spline" interpolation.)

In your case, it would be:

new = zoom(data, (55/64.0, 100/64.0, 60/64.0), order=typeofinterpolationyouwant)

You'll also need to consider how you'd like the boundaries handled. The default is to treat any values outside the original array as 0. With spline interpolation, this commonly leads to strong artifacts near the edges of the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM