8000 BUG: `np.unique_inverse` output has wrong shape · Issue #25552 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: np.unique_inverse output has wrong shape #25552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jakevdp opened this issue Jan 8, 2024 · 0 comments · Fixed by #25553
Closed

BUG: np.unique_inverse output has wrong shape #25552

jakevdp opened this issue Jan 8, 2024 · 0 comments · Fixed by #25553
Labels

Comments

@jakevdp
Copy link
Contributor
jakevdp commented Jan 8, 2024

Describe the issue:

According to the unique_inverse specification, the inverse_indices output of np.unique_inverse should have the same shape as the input:

second element must have the field name inverse_indices and must be an array containing the indices of values that reconstruct x. The array must have the same shape as x and have the default array index data type.

In NumPy's current implementation, inverse_indices is a flattened array.

A similar issue exists for numpy.unique_all.

Reproduce the code example:

import numpy as np
x = np.ones((2, 3))
out = np.unique_inverse(x)
assert out.inverse_indices.shape == x.shape, f"{out.inverse_indices.shape=} {x.shape=}"

Error message:

AssertionError: out.inverse_indices.shape=(6,) x.shape=(2, 3)

Python and NumPy Versions:

>>> import sys, numpy; print(numpy.__version__); print(sys.version)
2.0.0.dev0+git20240106.42fef42
3.9.6 (default, May  7 2023, 23:32:44) 
[Clang 14.0.3 (clang-1403.0.22.14.1)]

Runtime Environment:

>>> import numpy; print(numpy.show_runtime())
[{'numpy_version': '2.0.0.dev0+git20240106.42fef42',
  'python': '3.9.6 (default, May  7 2023, 23:32:44) \n'
            '[Clang 14.0.3 (clang-1403.0.22.14.1)]',
  'uname': uname_result(system='Darwin', node='jmdg-macbookpro.roam.internal', release='23.2.0', version='Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000', machine='arm64')},
 {'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
                      'found': ['ASIMDHP'],
                      'not_found': ['ASIMDFHM']}}]
@jakevdp jakevdp changed the title BUG: np.unique_inverse output has wrong shape BUG: np.unique_inverse output has wrong shape Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant
0