Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using an inline if then else statement might do it. Below, I assume the equations involved are rational functions, but it works for that case. You might be able to adapt this idea to your specific situation.

var('a x y')
eq_y1 = y == a/x
eq_y2 = y == a*x
eq_y3 = y == a^x

def fun_loop(in_array):
    out_array1 = np.zeros_like(in_array)
    out_array2 = np.zeros_like(in_array)
    out_array3 = np.zeros_like(in_array)
    for i in srange(len(in_array)):
        in_list = in_array[i]
        for j in srange(len(in_list) - 1):
            vdict = {}
            vdict[a] = in_array[i][j]
            vdict[x] = in_array[i][j+1]
            out_array1[i,j] = eq_y1.rhs().subs(vdict) if eq_y1.rhs().denominator().subs(vdict)!=0 else 0
            out_array2[i,j] = eq_y2.rhs().subs(vdict)
            out_array3[i,j] = eq_y3.rhs().subs(vdict)
    return [out_array1, out_array2, out_array3]
in_array = np.array([[3,2,1],[2,1,3],[-3,-1,-2]])