我正在尝试将聚类应用于数据集。在此之前,我必须将图划分为 n 个簇,但我不知道该怎么做。
假设 numpy 向量a和矩阵b如下:
import numpy as np
a = np.array([1,2])
b = np.array([[3,4],[5,6]])
Run Code Online (Sandbox Code Playgroud)
我想将向量a连接到矩阵 b 的每一行中。预期输出如下:
output=np.array([[1,2,3,4],[1,2,5,6]])
Run Code Online (Sandbox Code Playgroud)
我有一个工作代码如下:
output=np.array([np.concatenate((a,row)) for row in b] )
Run Code Online (Sandbox Code Playgroud)
有没有更快的 numpy 函数来执行这样的任务?任何建议表示赞赏!
我正在编写一个程序,需要对一些> 200、300 元素数组的数据集应用 K 均值聚类。有人可以给我提供一个代码链接,并解释一下- 1. 通过肘部方法找到 k 2. 应用 k 均值方法并获取质心数组
我自己搜索了上面的内容,但没有找到任何对代码有明确解释的内容。PS我正在Google Colab工作,所以如果有相同的具体方法,请提出建议
我尝试了下面的代码,但是,我不断收到以下错误 -
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
TypeError: float() argument must be a string or a number, not 'list'
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
<ipython-input-70-68e300fd4bf8> in <module>()
24
25 # step 1: find optimal k (number of clusters)
---> 26 find_best_k()
27
3 frames
/usr/local/lib/python3.6/dist-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
83
84 """ …Run Code Online (Sandbox Code Playgroud)