r - 2路数组的张量分解
问题描述
我可以rTensor::cp
用来分解R
. 但是,分解 2-way array 会发生错误L[[i]] : subscript out of bounds
。如何分解2路数组?谢谢。
cp
适用于 3 路阵列。
library(rTensor)
a <- c(0.1,0.9)
b <- c(0.5,0.5)
c <- c(0.7,0.3)
tnsr <- as.tensor(outer(outer(a,b),c))
cpD <- cp(tnsr, num_components=1)
> $U[[1]]
> [,1]
> [1,] 0.1
> [2,] 0.9
> $U[[2]]
> [,1]
> [1,] -0.5
> [2,] -0.5
> $U[[3]]
> [,1]
> [1,] -0.7
> [2,] -0.3
2 路阵列发生错误。
tnsr <- as.tensor(outer(a,b))
cpD <- cp(tnsr, num_components=1)
> Error in L[[i]] : subscript out of bounds
解决方案
一种解决方法是将 2 路数组乘以 1 以使其成为 3 路数组。
tnsr = as.tensor(outer(outer(a,b),1))
cpD = cp(tnsr, num_components=1)
> $U[[1]]
> [,1]
> [1,] 0.1
> [2,] 0.9
> $U[[2]]
> [,1]
> [1,] -0.5
> [2,] -0.5
> $U[[3]]
> [,1]
> [1,] -1
推荐阅读
- javascript - (动态)生成包含 X 个数量行和 Y 个数量列的表
- javascript - 课堂分享按钮 onsharecomplete 和 onsharestart 属性不起作用
- c - 输出与输入不匹配(C语言)
- php - 提交表单 (wire:submit.prevent) 时,Laravel URL 通配符更改为“16”
- android - 是否可以从命令行调试 Android 应用程序?
- python - 如何将索引和列之间名称重叠的 DataFrame 传递给 JSON
- r - 在 Rshiny 的侧边栏面板中选择了未定义的列
- laravel - 使用 AWS Lambda 中托管的 Laravel 导入 Excel 时出现错误“touch():无法创建文件,因为只读文件系统
- google-app-engine - 从旧的高复制数据存储 (HRD) GAE 项目中删除域映射
- javascript - 反应原生的多个开关如何