adapted to another version of scipy, it's a pain ...