Closed
Description
I have an array of 2d-arrays that I wish to treat as single units.
>>> import numpy as np
>>> x = np.arange(4*3*2).reshape((4,3,2))
So I made a custom subarray dtype:
>>> blob_dtype = np.dtype((x.dtype, (3,2)))
But conversions to this new subarray dtype fail:
>>> y = x.flatten().view(blob_dtype)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: new type not compatible with array.
After looking at the code causing the failure I saw this was a viable workaround:
>>> void_dtype = np.dtype((np.void, x.dtype.itemsize*3*2))
>>> y = x.flatten().view(void_dtype).view(blob_dtype)
Which seems to work, but I may be missing something fundamental about how subarray dtypes work.
My end goal is to filter out unique subarrays from a very large dataset.
Metadata
Metadata
Assignees
Labels
No labels