added a pure numpy version to work on noncontiguous memory