8000 Converting array to subarray dtype requires bogus intermediary dtype · Issue #7273 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Converting array to subarray dtype requires bogus intermediary dtype #7273
Closed
@machinaut

Description

@machinaut

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0