I have a numpy array A which looks like this:
array([list(['nan', 'nan']),
list(['nan', 'nan', 'apple', 'apple', 'banana', 'nan', 'nan']),
list(['red', 'red']), ...,
list(['nan', 'festival'])], dtype=object)
I want to convert this to an array in which each list contains only unique elements. For example, I want the above array to get converted to:
['nan'],['nan','apple','banana'],['red'],...,['nan','festival']
I have tried doing this:
output = []
for i in A:
output.append(np.unique(i))
output
The output which I get doing this is not desired and currently looks like this:
[array(['nan'], dtype='<U3'),
array(['nan'], dtype='<U3'),
array(['nan'], dtype='<U3'),....]
What can be done?
[array(['nan'], dtype='<U3'), array(['apple', 'banana', 'nan'], dtype='<U6'), array(['red'], dtype='<U3'), array([Ellipsis], dtype=object), array(['festival', 'nan'], dtype='<U8')]for me.['nan'],['nan','apple','banana'],['red'],...,['nan','festival']setinstead ofunique