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'
Appreciate the help and suggestion to make it work
I think you need to call
cupy.unique(codes)
instead ofcodes.unique()
like you could if it were a regular NumPy array. Docs: https://docs.cupy.dev/en/stable/reference/generated/cupy.unique.htmlIt was added in this PR: https://github.com/cupy/cupy/pull/1140 which as you may be able to see did not add it as a method on the array type.