我试图在scipy中使用kmeans聚类,正是这里的一个:
我想要做的是转换列表列表,如下所示:
data without_x[
[0,20.0,1.0,48.0,1224.0,125.5,3156.0,0],[0,22.5,56.0,41.5,85.5,1495.0,3496.5,2715.0,5566.5,0]
]
进入一个ndarry,以便与Kmeans方法一起使用.当我尝试将列表列表转换为ndarray时,我得到一个空数组,从而排除了整个分析. ndarray的长度是可变的,它取决于收集的样本数量.但是我可以轻松搞定
LEN(data_without_x)
这是返回空列表的代码片段.
import numpy as np
import "other functions"
data,data_without_x = data_preparation.generate_sampled_pdf()
nodes_stats,k,list_of_list= result_som.get_number_k()
data_array = np.array(data_without_x)
whitened = whiten(data_array)
centroids,distortion = kmeans(whitened,int(k),iter=100000)
___________________________
this is the data array[[ 0. 0. 0. ...,0. 0. 0.]
[ 0. 0. 0. ...,0. 0. 0.]
...,[ 0. 0. 0. ...,0. 0. 0.]]
___________________________
This is the whitened array[[ nan nan nan ...,nan nan nan]
[ nan nan nan ...,nan nan nan]
...,[ nan nan nan ...,nan nan nan]]
___________________________
有没有人知道当我尝试将列表列表转换为numpy.array时会发生什么?
谢谢你的帮助
最佳答案
原文链接:https://www.f2er.com/python/439570.html