I am trying to normalize a CSR matrix,
but I get this error: (*** TypeError: No matching signature found).
from sklearn.preprocessing import normalize
normalize(x_m, norm="l2", axis=1)
The matrix is 609186x849632 sparse matrix of type 'numpy.float16' with 189140200 stored elements in Compressed Sparse Row format
Actually I solved the problem. I think it is because of the data type. Changing np.float16
to np.float32
, solved the problem. I do not know why, this problem only happens with np.float16
data type.
from sklearn.preprocessing import normalize
columns_changed = []
for col in df.columns:
col_type = x_m[col].dtypes
if col_type == 'float16':
columns_changed.append(col)
x_m[col] = x_m[col].astype(np.float32)
normalize(x_m, norm="l2", axis=1)
for col in columns_changed:
x_m[col] = x_m[col].astype(np.float16)
x_m
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.