'cupy.core.core.ndarray' object has no attribute 'unique'

Viewed 1333

I was transforming categorical features using factorize() function which returns a tuple of a cupy array and strings. I assigned the cupy array into a variable named codes. However, I can't seem to get the unique values of codes using codes.unique()

It returns an error message:

AttrubuteError: 'cupy.core.core.ndarray' object has no attribute 'unique'

# use factorize to create continuous integers from a categorical feature (returns a tuple)
codes, uniques = df_train['product_id'].factorize()
codes.unique()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-59-27db0fac06a1> in <module>()
----> 1 codes.unique()

AttributeError: 'cupy.core.core.ndarray' object has no attribute 'unique'

code

Appreciate the help and suggestion to make it work

2 Answers

CuPy is designed to be highly compatible with NumPy, and in this case note that numpy.ndarray does not have a unique() method either; for both NumPy and CuPy it lives under the main namespace as a regular function (numpy.unique()/cupy.unique()). So it is an invalid usage not specific to CuPy IMHO.

Related