# Discrete Distribution with Non-Numeric Values

**URL:** <https://openturns.discourse.group/t/discrete-distribution-with-non-numeric-values/138>\
**Category:** Methodology\
**Tags:** distribution\
**Created:** [May 26, 2021, 10:54am UTC](https://openturns.discourse.group/t/discrete-distribution-with-non-numeric-values/138 "2021-05-26T10:54:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![StRuoff](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/struoff/32/159_2.png) [@StRuoff](https://openturns.discourse.group/u/StRuoff)\
**Post date:** [May 26, 2021, 10:54am UTC](https://openturns.discourse.group/t/discrete-distribution-with-non-numeric-values/138/1 "2021-05-26T10:54:08Z")

</div>

Is it possible in OpenTurns to create a discrete distribution containing non-numeric (string) values?

One application would be to select different turbulence models in my CFD code, that are given as string-values (e.g. ‘k-e’, ‘k-om’, ‘WALE’).

I am thinking of something like this, but it gives an error:

```python
points = ot.Sample([['k-e'], ['k-om'], ['WALE']])
weights = ot.Point([1, 1, 1])
my_distribution = ot.UserDefined(points, weights)

```

```bash
9376 def __init__ (self, *args):
-> 9377 _typ.Sample_swiginit(self, _typ.new_Sample(*args))
   9378 
   9379 def __eq__ (self, *args):
TypeError: Object passed as argument is not convertible to a Sample

```

If is not possible to handle non-numeric variables in OT, I would have to do a mapping of numerical values to the given strings in my Simulator Code.

---

<div class="post-metadata">

**Author:** ![JPelamatti](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/jpelamatti/32/101_2.png) [@JPelamatti](https://openturns.discourse.group/u/JPelamatti)\
**Post date:** [May 26, 2021, 2:20pm UTC](https://openturns.discourse.group/t/discrete-distribution-with-non-numeric-values/138/2 "2021-05-26T14:20:38Z")

</div>

Hello,  
To the best of my knowledge, all of OpenTURNS’ distributions can only return numerical values (e.g., floats, integers, arrays), and therefore you would probably need to resort to a mapping before running the simulator code, as you suggest.  
However, I’ll let the more experienced users correct me if I’m wrong.  
Cheers

---

<div class="post-metadata">

**Author:** ![regislebrun](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/regislebrun/32/154_2.png) [@regislebrun](https://openturns.discourse.group/u/regislebrun)\
**Post date:** [May 26, 2021, 2:51pm UTC](https://openturns.discourse.group/t/discrete-distribution-with-non-numeric-values/138/3 "2021-05-26T14:51:56Z")

</div>

Hi,  
@JPelamatti is perfectly right: OT is dedicated to the modeling of real-valued random vectors or random fields (to now). You can define discrete distributions (e.g. the **UserDefined** class you used) but you will have to map the _real valued_ realizations of such distributions into your set of strings. Be aware of the fact that _any_ distribution in OT is seen as the distribution of a random vector, so the corresponding realizations are vectors _even if these vectors are of dimension 1_. You can use the **Description** class to store your set of strings, but a pure Python list is the most natural option IMO. The conversion between these two types is automatic.  
You can use:

```auto
labels = ['k-e', 'k-om', 'WALE']
index = [[0], [1], [2]]
my_distribution = ot.UserDefined(index)
sample_labels = [labels[int(x[0])] for x in my_distribution.getSample(12)]

```

to generate a list of 12 randomly chosen labels:

```auto
['k-e', 'WALE', 'k-e', 'k-e', 'k-om', 'WALE', 'k-om', 'WALE', 'k-e', 'k-om', 'WALE', 'k-e']

```

Cheers

Régis
