Skip to content
Advertisement

Way to create numpy array to contain only unique elements for lists within it

I have a numpy array A which looks like this:

JavaScript

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:

JavaScript

I have tried doing this:

JavaScript

The output which I get doing this is not desired and currently looks like this:

JavaScript

What can be done?

Advertisement

Answer

JavaScript

try via list comprehension:

JavaScript

OR

JavaScript

output of out:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement