numpy.array.tostring doesn\'t seem to preserve information about matrix dimensions (see this question), requiring the user to issue a call to numpy.array.
numpy.array.tostring
numpy.array.
Try using numpy.array_repr or numpy.array_str.
numpy.array_repr
numpy.array_str