How to resolve "incorrect number of dimensions" error