## SOLVED: Replace items in list with another items (small lists) depending on several conditions

motaha:

I have a list of numbers and I want to replace each number with a list binary pattern depending on several conditions. I have a working code for doing so, but I am wondering if there is a faster more efficient one because if I wanted to add more conditions.

Thanks

``````import numpy as np
n = []
z = np.linspace(0,5,8)
t = [3.8856, 4.1820, 2.3040, 1.0197, 0.4295, 1.5178, 0.3853, 4.2848, 4.30911, 3.2299, 1.8528, 0.6553, 3.3305, 4.1504, 1.8787]
for i in t:
if i>=z and i<z:
n.extend([0,0,0,0,0])
elif i>=z and i<z:
n.extend([0,0,0,0,1])
elif i>=z and i<z:
n.extend([0,0,0,1,0])
elif i>=z and i<z:
n.extend([0,0,0,1,1])
elif i>=z and i<z:
n.extend([0,0,1,0,0])
elif i>=z and i<z:
n.extend([0,0,1,0,1])
elif i>=z and i<z:
n.extend([0,0,1,1,0])
new_n = np.asarray(n).reshape(len(t),5) # new_n is the final pattern I want.
```
```

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots