Require ndim to be strictly between 0 and the dimension of the input matrix