When casting dtypes, prefer numpy.asarray instead of ndarray.astype.  (The former avoids unecessary copies.)