I have a nested numpy array - it contains a lot of other numpy sub-arrays, but the sub-arrays have different lengths. The main array arr_main looks something like this:
>>> print(main_arr)
array([[array([3.5525, ..., 4.0138, 4.0139], dtype=float32)],
[array([3.5525, ..., 4.0138, 4.0139], dtype=float32)],
...
[array([3.5525, ..., 4.0138, 4.0139], dtype=float32)]],
dtype=object)
What I want to do is to extract only the unique sub-arrays from the big, main array, so I want to do something like
np.unique(main_arr)
but this results in the error message ValueError: operands could not be broadcast together with shapes (4613,) (4615,). I guess, this is due to some sub-arrays having different lengths.
How can I extract the unique sub-arrays from main_arr? If you know some solution that is not relying on numpy it will be also appreciated! tnx
uniqueworks by sorting the entries so identical ones arecnext to each other. That meansa>bcomparjson has to make sense. Another approach is use pythonset, but that requires hashable objects, ,ike tuples, not arrays. Separating your arrays into groups of like sized ones may be the only way to go. You need to think more about what makes your arrays 'unique', and not depend on some numpy magic to do all the 'thinking'.