# fourier_encode#

ivy.fourier_encode(x, max_freq, /, *, num_bands=4, linear=False, concat=True, flatten=False)[source]#

Pad an array with fourier encodings.

Parameters:
• x (`Union`[`Array`, `NativeArray`]) – Input array to encode.

• max_freq (`Union`[`float`, `Array`, `NativeArray`]) – The maximum frequency of the encoding.

• num_bands (`int`, default: `4`) – The number of frequency bands for the encoding. Default is 4.

• linear (`bool`, default: `False`) – Whether to space the frequency bands linearly as opposed to geometrically. Default is `False`.

• concat (`bool`, default: `True`) – Whether to concatenate the position, sin and cos values, or return separately. Default is `True`.

• flatten (`bool`, default: `False`) – Whether to flatten the position dimension into the batch dimension. Default is False.

Return type:

`Union`[`Array`, `NativeArray`, `Tuple`]

Returns:

ret – New array with the final dimension expanded, and the encodings stored in this channel.

Examples

```>>> x = ivy.array([1,2,3])
>>> y = 1.5
>>> z = ivy.fourier_encode(x,y)
>>> print(z)
ivy.array([[ 1.0000000e+00, 1.2246468e-16, 0.0000000e+00, 0.0000000e+00,
0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00,
1.0000000e+00],
[ 2.0000000e+00, -2.4492936e-16, 0.0000000e+00, 0.0000000e+00,
0.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00,
1.0000000e+00],
[ 3.0000000e+00, 3.6739404e-16, 0.0000000e+00, 0.0000000e+00,
0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00,
1.0000000e+00]])
```
```>>> x = ivy.array([3,10])
>>> y = 2.5
>>> z = ivy.fourier_encode(x, y, num_bands=3)
>>> print(z)
ivy.array([[ 3.0000000e+00,  3.6739404e-16,  3.6739404e-16, 3.6739404e-16,
-1.0000000e+00, -1.0000000e+00, -1.0000000e+00],
[ 1.0000000e+01, -1.2246468e-15, -1.2246468e-15, -1.2246468e-15,
1.0000000e+00,  1.0000000e+00,  1.0000000e+00]])
```
Array.fourier_encode(self, max_freq, /, *, num_bands=4, linear=False, concat=True, flatten=False)[source]#

ivy.Array instance method variant of ivy.fourier_encode. This method simply wraps the function, and so the docstring for ivy.fourier_encode also applies to this method with minimal changes.

Parameters:
• self (`Array`) – input array to encode

• max_freq (`Union`[`float`, `Array`, `NativeArray`]) – The maximum frequency of the encoding.

• num_bands (`int`, default: `4`) – The number of frequency bands for the encoding. Default is 4.

• linear (`bool`, default: `False`) – Whether to space the frequency bands linearly as opposed to geometrically. Default is `False`.

• concat (`bool`, default: `True`) – Whether to concatenate the position, sin and cos values, or return separately. Default is `True`.

• flatten (`bool`, default: `False`) – Whether to flatten the position dimension into the batch dimension. Default is `False`.

Return type:

`Union`[`Array`, `NativeArray`, `Tuple`]

Returns:

ret – New array with the final dimension expanded, and the encodings stored in this channel.

Examples

```>>> x = ivy.array([1, 2, 3])
>>> y = 1.5
>>> z = x.fourier_encode(y)
>>> print(z)
ivy.array([[ 1.0000000e+00, 1.2246468e-16, 0.0000000e+00, 0.0000000e+00,
0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00,
1.0000000e+00],
[ 2.0000000e+00, -2.4492936e-16, 0.0000000e+00, 0.0000000e+00,
0.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00,
1.0000000e+00],
[ 3.0000000e+00, 3.6739404e-16, 0.0000000e+00, 0.0000000e+00,
0.0000000e+00, -1.0000000e+00, 1.0000000e+00, 1.0000000e+00,
1.0000000e+00]])
```
```>>> x = ivy.array([3, 10])
>>> y = 2.5
>>> z = x.fourier_encode(y, num_bands=3)
>>> print(z)
ivy.array([[ 3.0000000e+00,  3.6739404e-16,  3.6739404e-16,  3.6739404e-16,
-1.0000000e+00, -1.0000000e+00, -1.0000000e+00],
[ 1.0000000e+01, -1.2246468e-15, -1.2246468e-15, -1.2246468e-15,
1.0000000e+00,  1.0000000e+00,  1.0000000e+00]])
```
Container.fourier_encode(self, max_freq, /, *, num_bands=4, linear=False, flatten=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

ivy.Container instance method variant of ivy.fourier_encode. This method simply wraps the function, and so the docstring for ivy.fourier_encode also applies to this method with minimal changes.

Parameters:
• self (`Container`) – Input container to apply fourier_encode at leaves.

• max_freq (`Union`[`float`, `Array`, `NativeArray`, `Container`]) – The maximum frequency of the encoding.

• num_bands (`Union`[`int`, `Container`], default: `4`) – The number of frequency bands for the encoding. Default is 4.

• linear (`Union`[`bool`, `Container`], default: `False`) – Whether to space the frequency bands linearly as opposed to geometrically. Default is `False`.

• flatten (`Union`[`bool`, `Container`], default: `False`) – Whether to flatten the position dimension into the batch dimension. Default is `False`.

• key_chains (`Optional`[`Union`[`List`[`str`], `Dict`[`str`, `str`], `Container`]], default: `None`) – The key-chains to apply or not apply the method to. Default is `None`.

• to_apply (`Union`[`bool`, `Container`], default: `True`) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is `True`.

• prune_unapplied (`Union`[`bool`, `Container`], default: `False`) – Whether to prune key_chains for which the function was not applied. Default is `False`.

• map_sequences (`Union`[`bool`, `Container`], default: `False`) – Whether to also map method to sequences (lists, tuples). Default is `False`.

• dtype – Data type of the returned array. Default is `None`.

• out – Optional output container. Default is `None`.

Return type:

`Container`

Returns:

ret – New container with the final dimension expanded of arrays at its leaves, and the encodings stored in this channel.

Examples

```>>> x = ivy.Container(a = ivy.array([1,2]),
...                   b = ivy.array([3,4]))
>>> y = 1.5
>>> z = x.fourier_encode(y)
>>> print(z)
{
a: (<class ivy.data_classes.array.array.Array> shape=[2, 9]),
b: (<class ivy.data_classes.array.array.Array> shape=[2, 9])
}
```
```>>> x = ivy.Container(a = ivy.array([3,10]),
...                   b = ivy.array([4,8]))
>>> y = 2.5
>>> z = x.fourier_encode(y,num_bands=3)
>>> print(z)
{
a: (<class ivy.data_classes.array.array.Array> shape=[2, 7]),
b: (<class ivy.data_classes.array.array.Array> shape=[2, 7])
}
```