c - 忽略:我只是重命名了标题来尝试一下
问题描述
我正在尝试一个一个地在数组中分配一个数字。如果指针指向数组的第一个元素,则表示数组为空,将分配一个数字。但由于某种原因,它似乎没有将指针移动到下一个元素。我怎样才能解决这个问题?
unsigned char number= '1';
unsigned char array[8];
int count = 0;
unsigned char *ptr;
int main(){
while(count < 5){
reserve();
count ++;
ptr++; //move to next element
}
}
void reserve(void){
if(ptr = array){ //if pointer is at the first element of the
*ptr = number; //array then it means it's empty
}
else{ //not empty array
*ptr = number;
}
}
解决方案
In [1]: from sklearn.feature_extraction.text import CountVectorizer
...:
...: text = ["London Paris London", "Paris Paris London"]
...: cv = CountVectorizer()
...: count_matrix = cv.fit_transform(text)
...:
结果是scipy.sparse
模块中定义的矩阵。它可以以多种方式显示:
In [2]: count_matrix
Out[2]:
<2x2 sparse matrix of type '<class 'numpy.int64'>'
with 4 stored elements in Compressed Sparse Row format>
In [3]: print(count_matrix)
(0, 0) 2
(0, 1) 1
(1, 0) 1
(1, 1) 2
In [4]: count_matrix.toarray()
Out[4]:
array([[2, 1],
[1, 2]])
In [5]: count_matrix.A # shorthand for toarray()
Out[5]:
array([[2, 1],
[1, 2]])
在这种情况下,矩阵不是“稀疏”的,即所有值都不为零。但一般来说,当许多值为零时使用这种类型的矩阵。通常我们定义这样一个矩阵
from scipy import sparse
M = sparse.csr_matrix(...) # see docs
sklearn
可以在其某些函数中使用稀疏矩阵输入,并在这种情况下创建一个。有关更多详细信息,请参阅CountVectorizer
文档。
推荐阅读
- scala - 等待期货列表 VS 等待单个期货
- java - 在 java 应用程序中为 swagger-fox 指定路径
- javascript - 通过 mvc 控制器安装 asp.net mvc excel 文件和 asp.net core web api 转发
- webrtc - 使用 WebAudioApi 和 WebAssembly 进行降噪
- python - 在 Pandas 中使用数据透视表时,有没有办法保持 nan 值存在?
- javascript - 如何从封装组件内的 onClick 隐藏封装组件的 div?
- sql - 如何提取年份列表和特定年份存在但前一年不存在的 ID 数量?
- javascript - ag-grid:如何使用 getChartModels() 生成的 ChartModel 呈现独立图表?
- html - 链接到根文件
- python - Python 访问类似命名的类和实例属性