PEP8 corrections
Removing code repetition
Minor refactoring
Downsampling of nD arrays