apply_mask() speedup

I did some optimizations in apply_mask(), that reduce execution time a little. 
Nothing spectacular is to be expected for standard cases (10-15% less time), but it could go much higher.

- Worst speedup (10% better): passing a compressed nifti filename to apply_mask with an empty cache (nifti file not previously loaded)

- Best speedup (2x): passing an uncompressed nifti filename to apply_mask with an empty cache (speedup is less with a full cache).

Included in this pull request is a new function as_ndarray() whose purpose in mainly to get rid of memmap objects efficiently. Comments on the function name welcome. 

I also checked that memory consumption was reasonable.

All the tests pass.