def save(self, obj):
    ' Subclass the save method, to save ndarray subclasses in npy\n            files, rather than pickling them. Of course, this is a\n            total abuse of the Pickler class.\n        '
    if ((self.np is not None) and (type(obj) in (self.np.ndarray, self.np.matrix, self.np.memmap))):
        size = (obj.size * obj.itemsize)
        if (self.compress and (size < (self.cache_size * _MEGA))):
            if (type(obj) is self.np.memmap):
                obj = self.np.asarray(obj)
            return Pickler.save(self, obj)
        if (not obj.dtype.hasobject):
            try:
                filename = ('%s_%02i.npy' % (self._filename, self._npy_counter))
                (obj, filename) = self._write_array(obj, filename)
                self._filenames.append(filename)
                self._npy_counter += 1
            except Exception:
                print(('Failed to save %s to .npy file:\n%s' % (type(obj), traceback.format_exc())))
    return Pickler.save(self, obj)
Subclass the save method, to save ndarray subclasses in npy
files, rather than pickling them. Of course, this is a
total abuse of the Pickler class.
def save(self, obj):
    ' Subclass the save method, to save ndarray subclasses in npy\n            files, rather than pickling them. Of course, this is a\n            total abuse of the Pickler class.\n        '
    if ((self.np is not None) and (type(obj) in (self.np.ndarray, self.np.matrix, self.np.memmap))):
        size = (obj.size * obj.itemsize)
        if (self.compress and (size < (self.cache_size * _MEGA))):
            if (type(obj) is self.np.memmap):
                obj = self.np.asarray(obj)
            return Pickler.save(self, obj)
        if (not obj.dtype.hasobject):
            try:
                filename = ('%s_%02i.npy' % (self._filename, self._npy_counter))
                (obj, filename) = self._write_array(obj, filename)
                self._filenames.append(filename)
                self._npy_counter += 1
            except Exception:
                print(('Failed to save %s to .npy file:\n%s' % (type(obj), traceback.format_exc())))
    return Pickler.save(self, obj)