How to convert a python set to a numpy array? How to convert a python set to a numpy array? arrays arrays

How to convert a python set to a numpy array?


Do:

>>> numpy.array(list(c))array([1, 4, 6])

And dtype is int (int64 on my side.)


Don't convert the numpy array to a set to perform exclusive-or. Use setxor1d directly.

>>> import numpy>>> a = numpy.array([1,2,3,4,5,6])>>> b = numpy.array([2,3,5])>>> numpy.setxor1d(a, b)array([1, 4, 6])


Try this.

numpy.array(list(c))

Converting to list before initializing numpy array would set the individual elements to integer rather than the first element as the object.