I want to be able to save my array subclass to a npy file, and recover the result later.
Something like:
>>> class MyArray(np.ndarray): pass
>>> data = MyArray(np.arange(10))
>>> np.save('fname', data)
>>> data2 = np.load('fname')
>>> assert isinstance(data2, MyArray) # raises AssertionError
the docs says (emphasis mine):
The format explicitly does not need to:
- [...]
- Fully handle arbitrary subclasses of numpy.ndarray. Subclasses will be accepted for writing, but only the array data will be written out. A regular numpy.ndarray object will be created upon reading the file. The API can be used to build a format for a particular subclass, but that is out of scope for the general NPY format.
So is it possible to make the above code not raise an AssertionError?