Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Applying a bivariate function to a list of couples

I have this function :

def F(v,a):
       if v > a :
            return 4*a - 3*(v-a)
       else : 
            return v - 2*(a-v)^2

I want to applied it to L2 define by

L0=list(range(4))
L1=list(range(4))
L2=flatten([[(v,a) for v in L0] for a in L1],max_level=1)

The only way I found to do this is the following

Vv=[(x,F(x[0],x[1])) for x in L2]
Vv

I wonder if therre is a more efficient, elegant way to do this like with apply_map().

Applying a bivariate function to a list of couples

I have this function :

def F(v,a):
       if v > a :
            return 4*a - 3*(v-a)
       else : 
            return v - 2*(a-v)^2

I want to applied it to L2 define by

L0=list(range(4))
L1=list(range(4))
L2=flatten([[(v,a) for v in L0] for a in L1],max_level=1)

The only way I found to do this is the following

Vv=[(x,F(x[0],x[1])) for x in L2]
Vv

I wonder if therre there is a more efficient, elegant way to do this like with apply_map().