there are numpy functions for that btw, no need to redefine