I made a slight change here since the "axis" argument was not doing anything, and was behaving inconsistently to how it normally behaves (axis=0 is along axis 0, axis=None is flat array).  I can revert this if it is an issue.