Fixed issue 3504

Fixed issue 3504 from numpy issues page:
https://github.com/numpy/numpy/issues/3504