How to implement guide with np.unique returning non-unique values when using return_counts=true on complex arrays
I'm dealing with I'm reviewing some code and After trying multiple solutions online, I still can't figure this out... I'm working with a strange scenario while trying to use `np.unique` from NumPy version 1.24.2 on an array of complex numbers. I expected to retrieve unique values along with their counts, but it seems that duplicate complex numbers are being returned as unique values, even though they are mathematically equivalent. Here's the code I'm working with: ```python import numpy as np # Sample complex array with repeated elements complex_array = np.array([1 + 2j, 1 + 2j, 2 + 3j, 2 + 3j, 3 + 4j]) # Attempting to get unique values and their counts unique_values, counts = np.unique(complex_array, return_counts=True) print("Unique values:", unique_values) print("Counts:", counts) ``` When I run this code, I get: ``` Unique values: [1.+2.j 2.+3.j 3.+4.j] Counts: [2 2 1] ``` However, I'm confused because the counts seem correct, but it feels like `np.unique` should be handling these complex numbers differently. I’ve tried converting the array to a different dtype or flattening it, but the same results continue. Is there something specific about how `np.unique` handles complex numbers that I'm missing? Any advice on how to ensure that truly equivalent complex numbers are treated as duplicates would be greatly appreciated! Could someone point me to the right documentation? I'm working in a Windows 10 environment. I'd love to hear your thoughts on this. Any suggestions would be helpful.