Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to define conditionaly two vector from one

I want to construct two vectors from one according to a condition.

zouzou=[random() for _ in range(0,10)]
len(zouzou)
zouzou
def conds(x,a) :
    if x > a : 
        return x
    else :  
        return 0
def condi(x,a) :
    if x <= a : 
        return x
    else :  
        return 0

when I try

show(conds(zouzou[2],.5))
show(condi(zouzou[3],.5))

I have no problems but when I use one or the other function to create a vector as in

zouzous=[conds(zouzou[_],.5) if _ in range(0,10)]

Sage return a syntax error.