def vdiff(x, vector):
    x = np.array(x)
    shape = x.shape
    ans = []
    for vi in vector:
        if vi.is_Symbol:
            tmp = []
            for e in x.ravel():
                tmp.append(e.diff(vi))
        else:
            subs = {}
            new_var = sympy.var('new_var')
            for s in vi.free_symbols:
                subs[s] = solve(vi - new_var, s)[0]
            tmp = []
            for e in x.ravel():
                e = e.subs(subs)
                e = e.diff(new_var)
                e = e.subs({new_var: vi})
                tmp.append(e.diff(new_var))
        ans.append(np.array(tmp))
    ans = [a.reshape(shape) for a in ans]
    return np.array(ans).swapaxes(0, 1)
dataset/ETHPy150Open saullocastro/mapy/mapy/sympytools/matrixtools.py/vdiff/swapped operands of `-`