[Scipy-svn] r2609 - trunk/Lib/io

scipy-svn at scipy.org scipy-svn at scipy.org
Wed Jan 24 17:37:32 CST 2007


Author: matthew.brett at gmail.com
Date: 2007-01-24 17:37:12 -0600 (Wed, 24 Jan 2007)
New Revision: 2609

Modified:
   trunk/Lib/io/npfile.py
Log:
Byteswap array to requred dtype when reading

Modified: trunk/Lib/io/npfile.py
===================================================================
--- trunk/Lib/io/npfile.py	2007-01-24 23:27:14 UTC (rev 2608)
+++ trunk/Lib/io/npfile.py	2007-01-24 23:37:12 UTC (rev 2609)
@@ -174,15 +174,14 @@
             shape = (shape,)
         dt = N.dtype(dt)
         dt_endian = self._endian_from_dtype(dt)
-        if not endian == 'dtype':
-            if dt_endian != endian:
-                dt = dt.newbyteorder(endian)
         sz = dt.itemsize * N.product(shape)
         buf = self.file.read(sz)
-        return N.ndarray(shape=shape,
+        arr = N.ndarray(shape=shape,
                          dtype=dt,
                          buffer=buf,
-                         order=order).copy()
-    
+                         order=order)
+        if (not endian == 'dtype') and (dt_endian != endian):
+            return arr.byteswap()
+        return arr.copy()
 
     fread = read



More information about the Scipy-svn mailing list