隐蔽到稀疏矩阵 - 类型错误:不支持类型转换:(dtype('0'),)

Poe*_*dit 4 python numpy scipy sparse-matrix

我正在尝试这样做:

  features = csr_matrix(features)
Run Code Online (Sandbox Code Playgroud)

这里features是一个<class 'numpy.ndarray'>看起来像如下:

[[51 1]
 [49 2]
 [47 2]
 ...
 [2 6]
 [20 2]
 [16 1]]
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

TypeError: no supported conversion for types: (dtype('O'),)
Run Code Online (Sandbox Code Playgroud)

这个错误是关于什么的,我该如何解决?

raf*_*elc 5

您可以重新定义您的 numpy 数组,dtype明确指定

features = np.array(features, dtype=float)
Run Code Online (Sandbox Code Playgroud)