import pyLHD
random_ls = pyLHD.LatinSquare(size = (4,4), seed = 1)
random_lsarray([[2, 3, 1, 2],
[4, 2, 4, 4],
[1, 4, 3, 3],
[3, 1, 2, 1]])
helpers.replace_values(arr, mapping)
Replace values in a numpy array based on a provided mapping dictionary
| Name | Type | Description | Default |
|---|---|---|---|
arr |
numpy.numpy.ArrayLike | A numpy array with values to be replaced. | required |
mapping |
dict | A dictionary where keys correspond to values in arr and values are the replacement values. |
required |
| Type | Description |
|---|---|
| numpy.numpy.ndarray | A numpy array with replaced values. |
| Type | Description |
|---|---|
| ValueError | If mapping does not contain the same unique values as in arr, or if the keys do not match. |
Examples:
array([[2, 3, 1, 2],
[4, 2, 4, 4],
[1, 4, 3, 3],
[3, 1, 2, 1]])
Consider the mapping \(1 \rightarrow 2, 2 \rightarrow 11, 3 \rightarrow 12, 4 \rightarrow 13\)