use*_*347 0 numpy python-2.7 scikit-learn
我有一个矩阵,命名X_test,从产生的sklearn.feature_extraction.text.CountVectorizer
.当我执行以下功能时:
import numpy as np
np.set_printoptions(threshold='nan')
print(X_test.shape)
print(X_test.size)
print(X_test.ndim)
print(np.array(X_test))
Run Code Online (Sandbox Code Playgroud)
我明白了:
(10211, 218904)
477881
2
(0, 934) 14
(0, 6773) 1
(0, 11035) 1
(0, 22362) 1
(0, 23619) 1
(0, 24812) 1
(0, 25224) 1
: :
(0, 64428) 1
(0, 66506) 1
Run Code Online (Sandbox Code Playgroud)
我不知道为什么尺寸不是矩阵尺寸(形状)的乘积.
从结果CountVectorizer
是一个scipy.sparse
矩阵,而不是一个NumPy的阵列.在这样的矩阵上,np.size
报告实际存储的元素的数量,这些元素可以(应该)远小于shape
.
(另外,要将其转换为数组,请使用该toarray
方法,但请注意,您将创建一个大小为几GB的数组,而不是用于稀疏格式的几个MB.)
归档时间: |
|
查看次数: |
66 次 |
最近记录: |