pure python version (without numpy)