> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# replace()

<span id="atoti.array.replace" />

> atoti.array.replace(<br />
>     *measure*: VariableMeasureConvertible,<br />
>     *replacements*: [Mapping](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)\[[float](https://docs.python.org/3/library/functions.html#float), [float](https://docs.python.org/3/library/functions.html#float)] | [Mapping](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)\[[int](https://docs.python.org/3/library/functions.html#int), [int](https://docs.python.org/3/library/functions.html#int)],<br />
>     /,<br />
> ) → MeasureDefinition

Return a measure where elements equal to a key of the *replacements* mapping are replaced with the corresponding value.

### Parameters

<h4 id="atoti.array.replace.measure">
  *measure*
</h4>

The array measure in which to replace the elements.

<h4 id="atoti.array.replace.replacements">
  *replacements*
</h4>

The mapping from the old values to the new ones.

***

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> import math
>>> df = pd.DataFrame(
...     columns=["Store ID", "New Price", "Old Price"],
...     data=[
...         ("Store 1", [12, 6, 2, 20], [6, 3, 0, 10]),
...         ("Store 2", [16, 8, 12, 15], [4, 4, 6, 3]),
...         ("Store 3", [8, -10, 0, 33], [8, 0, 2, 11]),
...     ],
... )
>>> table = session.read_pandas(df, keys={"Store ID"}, table_name="Prices")
>>> cube = session.create_cube(table)
>>> l, m = cube.levels, cube.measures
>>> m["Price ratio"] = m["New Price.SUM"] / m["Old Price.SUM"]
>>> m["Price ratio without infinity"] = tt.array.replace(
...     m["Price ratio"], {math.inf: 1, -math.inf: -1}
... )
>>> m["Price ratio"].formatter = "ARRAY[',']"
>>> m["Price ratio without infinity"].formatter = "ARRAY[',']"
>>> cube.query(
...     m["Price ratio"],
...     m["Price ratio without infinity"],
...     levels=[l["Store ID"]],
... )
                    Price ratio Price ratio without infinity
Store ID
Store 1    2.0,2.0,Infinity,2.0              2.0,2.0,1.0,2.0
Store 2         4.0,2.0,2.0,5.0              4.0,2.0,2.0,5.0
Store 3   1.0,-Infinity,0.0,3.0             1.0,-1.0,0.0,3.0
```
