lundi 11 janvier 2021

Create IF statement from a variable size array

I have a lnprior function which should change according to the parameters I want to fit while some are kept fixed. Let's say I have

p0 = [1,20]
p1 = [[0,2],[10,30]]

Basically I have:

a, b = p0
a_, b_ = p1
if (a_[0] < a < a_[1]) and (b_[0] < b < b_[1]):

However, p0 and p1 can have a changing dimension as for instance

p0 = [1,20, 300]
p1 = [[0,2],[10,30],[200, 400]]

In that case the IF condition should be:

a, b, c = p0
a_, b_, c_ = p1
if (a_[0] < a < a_[1]) and (b_[0] < b < b_[1]) and (c_[0] < c < c_[1])

Is there a way to automatically create the IF statement according to the size of p0 (in my real code p0 is a dictionary, which might be easier to manipulate)?

Aucun commentaire:

Enregistrer un commentaire