following problem: Having a base triple (0,1,0)
Now I try to create a list of changed triples in a given range.
The constraints:
- triple[0] and triple[2] have should have a maximum of r, such as r=0.2
- sum(triple) = 1
- triple[0] needn’t to be equals triple[1] and should be increased by a given stepwise-parameter s, such as s= 0.02
In this above mentioned example our methode should create
lst = [(0.0, 1, 0.0),(0.02, 0.98, 0.), (0.04, 0.96,0), (0.04,0.94, 0.02), (0.06,0.94,0), (0.06, 0.92, 0.02), (0.06, 0.9, 0.04), ...]
Is there any pretty way to do this?
Maybe you have an idea to create these list without nested loops (probably with numpy?).
Thanks a lot!
Here’s a list comprehension that should provide all 3-tuples that meet your constraints (as I understand them). Its a bit more clunky than I’d like due to the range function only accepting integers:
Results:
The first and last values only go up to 0.18 in this code, and I’m not sure if that’s desirable or not (is the constraint < r or <= r?). It shouldn’t be too hard to tweak, if you want it the other way.