---
title: "ArrayResample"
language: "en"
type: "Symbol"
summary: "ArrayResample[array, {n1, n2, ...}] resamples array to have dimensions {n1, n2, ...}. ArrayResample[array, dspec] resamples array according to the dimension specification dspec. ArrayResample[array, dspec, scheme] specifies resampling scheme, either point or bin based. ArrayResample[array, dspec, scheme, {{xmin, xmax}, ...}] resamples only the data in the specified subrange {{xmin, xmax}, ...}."
keywords: 
- resize
- resample
- resampling
- interpolateion
- decimation
- rescale
- scale
- subsampling
- upsampling
- interp1
- interp2
- interp3
- interpn
- interpft
canonical_url: "https://reference.wolfram.com/language/ref/ArrayResample.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Rearranging & Restructuring Lists"
    link: "https://reference.wolfram.com/language/guide/RearrangingAndRestructuringLists.en.md"
  - 
    title: "Creating & Importing Signals"
    link: "https://reference.wolfram.com/language/guide/CreatingAndImportingSignals.en.md"
  - 
    title: "Structure Matrices & Convolution Kernels"
    link: "https://reference.wolfram.com/language/guide/StructureMatricesAndConvolutionKernels.en.md"
related_functions: 
  - 
    title: "ListInterpolation"
    link: "https://reference.wolfram.com/language/ref/ListInterpolation.en.md"
  - 
    title: "Interpolation"
    link: "https://reference.wolfram.com/language/ref/Interpolation.en.md"
  - 
    title: "ImageResize"
    link: "https://reference.wolfram.com/language/ref/ImageResize.en.md"
  - 
    title: "Upsample"
    link: "https://reference.wolfram.com/language/ref/Upsample.en.md"
  - 
    title: "Downsample"
    link: "https://reference.wolfram.com/language/ref/Downsample.en.md"
  - 
    title: "Dimensions"
    link: "https://reference.wolfram.com/language/ref/Dimensions.en.md"
  - 
    title: "ArrayPad"
    link: "https://reference.wolfram.com/language/ref/ArrayPad.en.md"
  - 
    title: "ArrayFilter"
    link: "https://reference.wolfram.com/language/ref/ArrayFilter.en.md"
related_tutorials: 
  - 
    title: "Image Processing"
    link: "https://reference.wolfram.com/language/tutorial/ImageProcessing.en.md"
---
# ArrayResample

ArrayResample[array, {n1, n2, …}] resamples array to have dimensions {n1, n2, …}.

ArrayResample[array, dspec] resamples array according to the dimension specification dspec.

ArrayResample[array, dspec, scheme] specifies resampling scheme, either point or bin based. 

ArrayResample[array, dspec, scheme, {{xmin, xmax}, …}] resamples only the data in the specified subrange {{xmin, xmax}, …}.

## Details and Options

* ``ArrayResample`` can be used for resampling data arrays based on a large selection of interpolation and approximation models.

* ``ArrayResample`` works with data arrays of any depth.

* The dimension specification ``dspec`` can be of the form:

|                     |                                                                                |
| ------------------- | ------------------------------------------------------------------------------ |
| n                   | n samples                                                                      |
| Scaled[s]           | rescale sampling resolution by factor s                                        |
| All                 | preserve dimension                                                             |
| Automatic           | preserve dimension ratios                                                      |
| {dspec1, …, dspeck} | resample up to the $k$$$^{\text{th}}$$ dimension |

* For a multidimensional array, the notation ``n`` is taken to be equivalent to ``{n, Automatic, …}`` and ``{n}`` equivalent to ``{n, All, …}``.

* The dimension ratios for an array of dimensions $\left\{d_1,d_2,d_3,\ldots \right\}$ is taken to be $\left\{1,d_2/d_1,d_3/d_1,\ldots \right\}$.

* The ``scheme`` determines the location of sample and resample positions and can be of the form:

|                    |                                       |
| ------------------ | ------------------------------------- |
| "Point"            | point sampling (default)              |
| "Bin"              | bin sampling                          |
| {"Bin", alignment} | bin sampling with specified alignment |

[image]

* For input data of length ``n`` the ``"Point"`` resampling scheme assumes a data range from ``1`` to ``n`` and the ``"Bin"`` scheme assumes a data range from ``0`` to ``n`` with the alignment indicating the sample location within each bin.

* Bin alignment ``alignment`` can be ``Left``, ``Center``, ``Right`` or any number between $-1$ (``Left``) and 1 (``Right``).

* The data range can be modified using the ``DataRange`` option.

* By default, the data is resampled on the entire data domain, ranging from 1 to $n$ for the ``"Point"`` scheme and from 0 to $n$ for the ``"Bin"`` scheme. Use the ``DataRange`` option to modify the coordinates of the data domain.

* With a subrange ``{{xmin, xmax}, …}`` specified with respect to the ``DataRange``, only the data values in the given interval are resampled.  »

* The following options can be given:

|               |           |                                      |
| ------------- | --------- | ------------------------------------ |
| Antialiasing  | False     | apply antialiasing when downsampling |
| DataRange     | Automatic | range of the input data              |
| Padding       | "Fixed"   | padding method                       |
| Resampling    | Automatic | resampling method                    |

* For possible settings for ``Padding``, see the reference page for ``ArrayPad``.

## Examples (19)

### Basic Examples (2)

Subsample an array:

```wl
In[1]:= ArrayResample[{1, 2, 3, 4, 5}, 9]

Out[1]= {1, (3/2), 2, (5/2), 3, (7/2), 4, (9/2), 5}
```

Downsample an array:

```wl
In[2]:= ArrayResample[{1, 2, 3, 4, 5}, 3]

Out[2]= {1, 3, 5}
```

---

Resize a 2D array of data:

```wl
In[1]:=
ArrayResample[(⁠|   |   |   |
| - | - | - |
| 1 | 2 | 3 |
| 2 | 3 | 4 |
| 3 | 4 | 5 |⁠), 6]//MatrixForm

Out[1]//MatrixForm=
(⁠|        |        |        |        |        |        |
| ------ | ------ | ------ | ------ | ------ | ------ |
| 1      | (7/5)  | (9/5)  | (11/5) | (13/5) | 3      |
| (7/5)  | (9/5)  | (11/5) | (13/5) | 3      | (17/5) |
| (9/5)  | (11/5) | (13/5) | 3      | (17/5) | (19/5) |
| (11/5) | (13/5) | 3      | (17/5) | (19/5) | (21/5) |
| (13/5) | 3      | (17/5) | (19/5) | (21/5) | (23/5) |
| 3      | (17/5) | (19/5) | (21/5) | (23/5) | 5      |⁠)
```

### Scope (8)

#### Basic Uses (4)

Exact computation:

```wl
In[1]:= ArrayResample[{1, 2, 3}, 4]

Out[1]= {1, (5/3), (7/3), 3}
```

---

Precision of the input is preserved:

```wl
In[1]:= ArrayResample[{1.0000000000000000000, 2.0000000000000000000, 3.0000000000000000000, 4.0000000000000000000}, 6]

Out[1]= {1.000000000000000000, 1.600000000000000000, 2.200000000000000000, 2.800000000000000000, 3.400000000000000000, 4.000000000000000000}
```

---

Resizing a symbolic array:

```wl
In[1]:= ArrayResample[{a, b, c}, 5]

Out[1]= {a, (a/2) + (b/2), b, (b/2) + (c/2), c}
```

---

Resample a subdomain of the input signal:

```wl
In[1]:= input = Range[100];

In[2]:= ArrayResample[input, 20, "Point", {55, 63}]

Out[2]= {55, (1053/19), (1061/19), (1069/19), (1077/19), (1085/19), (1093/19), (1101/19), (1109/19), (1117/19), (1125/19), (1133/19), (1141/19), (1149/19), (1157/19), (1165/19), (1173/19), (1181/19), (1189/19), 63}
```

#### Output Dimensions (1)

With size specified as a scalar, output dimension is selected such that dimension ratio is preserved:

```wl
In[1]:=
ArrayResample[(⁠|   |   |   |
| - | - | - |
| 1 | 2 | 3 |
| 4 | 5 | 6 |⁠), 4]//MatrixForm

Out[1]//MatrixForm=
(⁠|   |        |        |   |        |        |   |
| - | ------ | ------ | - | ------ | ------ | - |
| 1 | (4/3)  | (5/3)  | 2 | (7/3)  | (8/3)  | 3 |
| 2 | (7/3)  | (8/3)  | 3 | (10/3) | (11/3) | 4 |
| 3 | (10/3) | (11/3) | 4 | (13/3) | (14/3) | 5 |
| 4 | (13/3) | (14/3) | 5 | (16/3) | (17/3) | 6 |⁠)

In[2]:= Dimensions[%]

Out[2]= {4, 6}
```

#### Sampling Schemes (3)

By default, the ``"Point"`` sampling scheme is used:

```wl
In[1]:= ArrayResample[{1, 2, 3}, 7, "Point"]

Out[1]= {1, (4/3), (5/3), 2, (7/3), (8/3), 3}
```

---

Use the ``"Bin"`` scheme, which uses center alignment by default:

```wl
In[1]:= ArrayResample[{1, 2, 3}, 6, "Bin"]

Out[1]= {1, (5/4), (7/4), (9/4), (11/4), 3}
```

Specify the alignment of the bins:

```wl
In[2]:= ArrayResample[{1, 2, 3}, 6, {"Bin", -1}]

Out[2]= {1, (3/2), 2, (5/2), 3, 3}
```

---

Generate a ``"Point"`` resampling with three times the input resolution:

```wl
In[1]:=
input = {2, 1, 3, 4, 2, 5};
m = Length[input];
s = 3;
res1 = ArrayResample[input, Scaled[s]]

Out[1]= {2, (5/3), (4/3), 1, (5/3), (7/3), 3, (10/3), (11/3), 4, (10/3), (8/3), 2, 3, 4, 5}
```

Compute the sampling positions:

```wl
In[2]:= pos = Range[1, m, (m - 1) / Round[s (m - 1)]]

Out[2]= {1, (4/3), (5/3), 2, (7/3), (8/3), 3, (10/3), (11/3), 4, (13/3), (14/3), 5, (16/3), (17/3), 6}

In[3]:= ListPlot[{Thread[{Range[m], input}], Thread[{pos, res1}]}, Joined -> {True, False}, PlotStyle -> {PointSize[.04], Automatic}, Mesh -> All]

Out[3]= [image]
```

### Options (5)

#### Antialiasing (1)

When downsampling, by default no antialiasing is happening:

```wl
In[1]:= data = {2, 1, 2, 1, 2, 1, 2};

In[2]:= ArrayResample[data, Scaled[1 / 2], Padding -> "Reflected"]

Out[2]= {2, 2, 2, 2}
```

With antialiasing, all samples that fall in between new samples are averaged:

```wl
In[3]:= ArrayResample[data, Scaled[1 / 2], Padding -> "Reflected", Antialiasing -> True]

Out[3]= {(3/2), (3/2), (3/2), (3/2)}
```

#### DataRange (1)

``DataRange`` specifies the domain of resampling. Subrange specification is defined with respect to this domain:

```wl
In[1]:= data = {0, 2, 0, 1, 4, 1, 9, 4, 4};
```

Resample the whole data:

```wl
In[2]:= ArrayResample[data, Scaled[2], "Point"]

Out[2]= {0, 1, 2, 1, 0, (1/2), 1, (5/2), 4, (5/2), 1, 5, 9, (13/2), 4, 4, 4}
```

Resample the first half using default ``DataRange -> {1, n}``, where ``n`` is the length of ``data`` :

```wl
In[3]:= ArrayResample[data, Scaled[2], "Point", {1, 5}]

Out[3]= {0, 1, 2, 1, 0, (1/2), 1, (5/2), 4}
```

Resample the first half of the data using a ``{0, 1}`` data range:

```wl
In[4]:= ArrayResample[data, Scaled[2], "Point", {0, 1 / 2}, DataRange -> {0, 1}]

Out[4]= {0, 1, 2, 1, 0, (1/2), 1, (5/2), 4}
```

#### Padding (2)

The default padding value is ``"Fixed"`` :

```wl
In[1]:= ArrayResample[{1, 2, 3}, 9, "Bin"]

Out[1]= {1, 1, (4/3), (5/3), 2, (7/3), (8/3), 3, 3}
```

Specify a different padding:

```wl
In[2]:= ArrayResample[{1, 2, 3}, 9, "Bin", Padding -> 0]

Out[2]= {(2/3), 1, (4/3), (5/3), 2, (7/3), (8/3), 3, 2}
```

---

By default, the same padding is used for all dimensions:

```wl
In[1]:=
ArrayResample[(⁠|   |   |   |
| - | - | - |
| 1 | 2 | 3 |
| 2 | 1 | 6 |
| 3 | 6 | 2 |⁠), 5, Resampling -> "Cubic", Padding -> 0]//N//MatrixForm

Out[1]//MatrixForm=
(⁠|         |          |         |         |         |
| ------- | -------- | ------- | ------- | ------- |
| 1.      | 1.41923  | 2.      | 2.875   | 3.      |
| 1.41923 | 0.818854 | 1.03701 | 3.53408 | 5.14952 |
| 2.      | 1.03701  | 1.      | 3.94856 | 6.      |
| 2.875   | 3.53408  | 3.94856 | 4.65985 | 4.42163 |
| 3.      | 5.14952  | 6.      | 4.42163 | 2.      |⁠)
```

Use different paddings for different dimensions:

```wl
In[2]:=
ArrayResample[(⁠|   |   |   |
| - | - | - |
| 1 | 2 | 3 |
| 2 | 1 | 6 |
| 3 | 6 | 2 |⁠), 5, Resampling -> "Cubic", Padding -> {0, "Fixed"}]//N//MatrixForm

Out[2]//MatrixForm=
(⁠|         |          |         |         |         |
| ------- | -------- | ------- | ------- | ------- |
| 1.      | 1.39952  | 2.      | 2.60048 | 3.      |
| 1.41923 | 0.814893 | 1.03701 | 3.05486 | 5.14952 |
| 2.      | 0.997595 | 1.      | 3.39952 | 6.      |
| 2.875   | 3.36424  | 3.94856 | 4.29297 | 4.42163 |
| 3.      | 4.90192  | 6.      | 4.30144 | 2.      |⁠)
```

#### Resampling (1)

By default, ``"Linear"`` resampling is used:

```wl
In[1]:= ArrayResample[{1, 2, 3}, 6]

Out[1]= {1, (7/5), (9/5), (11/5), (13/5), 3}
```

Use a different resampling scheme:

```wl
In[2]:= ArrayResample[{1, 2, 3}, 6, Resampling -> "Nearest"]

Out[2]= {1, 1, 2, 2, 3, 3}
```

``"Nearest"`` resampling averages the samples if the sampling position is halfway between samples:

```wl
In[3]:= ArrayResample[{1, 2, 3}, 5, Resampling -> "Nearest"]

Out[3]= {1, (3/2), 2, (5/2), 3}
```

Use ``"NearestLeft"`` or ``"NearestRight"`` for a bias to left or right for half-integer sampling positions:

```wl
In[4]:= ArrayResample[{1, 2, 3}, 5, Resampling -> "NearestLeft"]

Out[4]= {1, 1, 2, 2, 3}
```

### Applications (1)

Reduce the size of a dataset for faster visualization:

```wl
In[1]:= data = Import["http://exampledata.wolfram.com/hailey.dem.gz", "Data"];

In[2]:= (data2 = ArrayResample[N@data, Scaled[1 / 5]])//ReliefPlot

Out[2]= [image]

In[3]:= AbsoluteTiming[ReliefPlot[#];][[1]]& /@ {data, data2}

Out[3]= {1.07254, 0.0457567}
```

### Properties & Relations (2)

Compare array resampling for a few different kernels:

```wl
In[1]:=
a = {1, 3, 1, 2};
n = 25;
xpos = Array[#&, n, {1, Length[a]}];
Table[
	result = ArrayResample[a, n, Resampling -> ker];
	ListPlot[Transpose[{xpos, result}], PlotStyle -> PointSize[Medium], Epilog -> {Red, Line[Transpose[{Range[Length[a]], a}]]}, Axes -> {True, False}, PlotLabel -> ker], 
	{ker, {"Linear", "Cubic", "German"}}]

Out[1]= {[image], [image], [image]}
```

---

``Downsample`` can be used to downsample by an integer factor:

```wl
In[1]:= Downsample[Range[9], 2]

Out[1]= {1, 3, 5, 7, 9}

In[2]:= ArrayResample[Range[9], Scaled[1 / 2]]

Out[2]= {1, 3, 5, 7, 9}
```

### Possible Issues (1)

Exact computations are performed with integer data:

```wl
In[1]:= input = Range[100];

In[2]:= AbsoluteTiming[ArrayResample[input, 1000, Resampling -> "Cubic"];]

Out[2]= {0.282192, Null}
```

Apply ``N`` to integer data for faster computation:

```wl
In[3]:= AbsoluteTiming[ArrayResample[N@input, 1000, Resampling -> "Cubic"];]

Out[3]= {0.000722, Null}
```

## See Also

* [`ListInterpolation`](https://reference.wolfram.com/language/ref/ListInterpolation.en.md)
* [`Interpolation`](https://reference.wolfram.com/language/ref/Interpolation.en.md)
* [`ImageResize`](https://reference.wolfram.com/language/ref/ImageResize.en.md)
* [`Upsample`](https://reference.wolfram.com/language/ref/Upsample.en.md)
* [`Downsample`](https://reference.wolfram.com/language/ref/Downsample.en.md)
* [`Dimensions`](https://reference.wolfram.com/language/ref/Dimensions.en.md)
* [`ArrayPad`](https://reference.wolfram.com/language/ref/ArrayPad.en.md)
* [`ArrayFilter`](https://reference.wolfram.com/language/ref/ArrayFilter.en.md)

## Tech Notes

* [Image Processing](https://reference.wolfram.com/language/tutorial/ImageProcessing.en.md)

## Related Guides

* [Rearranging & Restructuring Lists](https://reference.wolfram.com/language/guide/RearrangingAndRestructuringLists.en.md)
* [Creating & Importing Signals](https://reference.wolfram.com/language/guide/CreatingAndImportingSignals.en.md)
* [Structure Matrices & Convolution Kernels](https://reference.wolfram.com/language/guide/StructureMatricesAndConvolutionKernels.en.md)

## History

* [Introduced in 2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md) \| [Updated in 2016 (11.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn110.en.md)