for i in range(n):
    for j in range(i + 1):
        A += F[i, j] * V[(i), :] * V[(j), :]
return A

def isaac_code(V, F):
    n, p = V.shape
F = F.copy()
F[np.triu_indices(n, 1)] = 0
M = V.reshape(n, 1, p) * V.reshape(1, n, p) * F.reshape(n, n, 1)
return M.sum((0, 1))
numpy векторизация двойного питона для цикла