Improvements to _read_or_write()

* add comment for documentation
* add check for array shape
* add an assertion