You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Python中通过rpy2调用dtwclust的tsclust,如何获取聚类分配?

获取dtwclust聚类结果的聚类分配(Python+rpy2)

在R中用Z@cluster访问S4对象的cluster槽位,对应到rpy2里,需要用slot()方法来获取这个槽位的值:

# 获取聚类分配的R向量
cluster_assignments = Z.slot("cluster")

如果需要转换成Python常用的数据结构,可以进一步处理:

  • 转为Python列表:
cluster_list = list(cluster_assignments)
  • 转为numpy数组(需提前安装numpy):
import numpy as np
cluster_array = np.array(cluster_assignments)

说明:tsclust返回的是S4类型的对象,rpy2中通过slot()方法访问这类对象的槽位,等价于R中的@操作符。

内容的提问来源于stack exchange,提问作者Giorgia Lotta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 15:20:22