如何将两个表相乘我有一个大数据表和一个标准化因子表。
数据表如下所示:
| ID | 类型 | 参数1 | 参数2 | 参数3 |
| 01 | 1 | 数据 | 数据 | 数据 |
| 02 | 1 | 数据 | 数据 | 数据 |
| 03 | 2 | 数据 | 数据 | 数据 |
| 04 | 2 | 数据 | 数据 | 数据 |
标准化因子表如下所示:
| 类型 | 参数1 | 参数2 | 参数3 |
| 1 | 归一化因子1 | 归一化因子2 | 归一化因子3 |
| 2 | 归一化因子4 | 归一化因子5 | 归一化因子6 |
如何根据类型和参数将第一个表乘以第二个表并获得如下所示的新表:
| ID | 类型 | 参数1 | 参数2 | 参数3 |
| 01 | 1 | 数据*标准化因子1 | 数据*标准化因子2 | 数据*标准化因子3 |
| 02 | 1 | 数据*标准化因子1 | 数据*标准化因子2 | 数据*标准化因子3 |
| 03 | 2 | 数据*归一化因子4 | 数据*标准化因子5 | 数据*标准化因子6 |
| 04 | 2 | 数据*归一化因子4 | 数据*标准化因子5 | 数据*标准化因子6 |
我的原始数据表的行和列都很大,因此我需要一个快速的解决方案。
非常感谢。
高级统计建模消费者和市场研究大规模定制质量和工艺工程回复:如何将两个表相乘这是一个例子
mat1 = [ 1 2 3, 4 5 6, 7 8 9, 10 11 12];
mat2 = [1 2 3 4, 5 6 7 8, 9 10 11 12];
finalMat = mat1 * mat2;
这是一个数据位于数据表中的示例
names default to here(1);
dt1 = data table("one");
dt2 = data table("two");
finalMat=dt1[0,0]*dt2[0,0];回复:如何将两个表相乘你好
我有两个矩阵要相乘,例如,第一个是 3X4 矩阵,第二个是 4X2 矩阵。 有人可以建议如何在 JMP Pro 16 中执行此矩阵乘法吗?
回复:如何将两个表相乘感谢您的更新,我尝试过,它适用于试验数据集。 然而,正如另一个人指出的那样,我确实遇到了性能问题。 因此我接受他的回答作为最佳解决方案。
回复:如何将两个表相乘你好,
我看了一下这个,注意到一旦表接近你的大小(实际上,早在这之前),就会出现性能墙。当我开始以大约 10K 的“块”处理表时,我能够稍微改进一些事情行乘 1K 列。 您可以调整尺寸来看看哪种效果最好,但这些尺寸似乎效果很好。
此方法不会创建新表 - 它会覆盖原始表...因此您需要保存原始表,然后以不同的名称保存结果。
下面的脚本做了一些假设,因为它只是为了说明总体概念 -
- 每个表中相应的列的顺序相同。
- 对于 p 个参数,主表有 p+2 列,因子表有 p+1 列。两个表中都没有其他列。
实际上加工一个 100 万行、1000 列的表的时间约为 40 秒……每个“块”大约需要 0.3 - 0.4 秒来处理。
表设置部分,用于模拟您拥有的表,花了一段时间......可能需要几分钟。 目前,该脚本是为较小的表设置的...修改 //table settings 注释下的行以更改此设置。
该代码既不优雅也不紧凑,但它的运行速度比我能想到的任何其他东西都要快(包括一次在整个块上使用元素乘法......出于某种原因,迭代列大约花费了一半的时间。 )不过,我没有尝试克雷格基于公式的方法。
需要进行初始排序,以避免必须使用 where() 获取行(如果必须这样做,则会大大减慢速度。)
干杯,
布雷迪
Names Default To Here( 1 );
//set limits on block size
blockRowLimit = 1e4;
blockColLimit = 1e3;
// table setup
rowsdt1 = 1e4;
colsdt1 = 1e2;
dt1 = As Table( (1 :: rowsDt1)` || J( rowsDt1, 1, Random Integer( 1, 2 ) ) || J( rowsdt1, colsdt1, Random Uniform() ), <<INVISIBLE></INVISIBLE>
回复:如何将两个表相乘循环并不容易;我认为这会做到这一点:
// make example tables. **save them** so virtual join works.
factorDT = New Table( "Imported Data 2",
New Column( "Type", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2] ) ),
New Column( "parameter1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1.1, 1.2] ) ),
New Column( "parameter2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0.8, 0.9] ) ),
New Column( "parameter3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1.1, 0.9] ) )
);
factorDT << save( "$temp/factor.jmp" );
dataDT = New Table( "Imported Data",
New Column( "ID", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
New Column( "Type", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 1, 2, 2] ) ),
New Column( "parameter1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
New Column( "parameter2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 3, 2, 1] ) ),
New Column( "parameter3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3, 3, 2] ) )
);
dataDT << save( "$temp/data.jmp" );
originalColumns = dataDT<<GETCOLUMNNAMES></GETCOLUMNNAMES>
- 在使用虚拟连接添加隐藏列之前捕获原始列
- 使用 \!" 构建表达式 e 以转义嵌入的引号
- 使用 write() 来调试您的工作,而不是打印
- <
回复:如何将两个表相乘谢谢,它适用于小数据集。 但表 1 中有数百万行,表 2 中只有两行。 因此我想避免创建另一个巨大的表。 如果我找不到更好的解决方案,我会尝试这个方法。
回复:如何将两个表相乘感谢你的回复。 但是,我有很多列,列名很复杂。 因此我想编写一个 for 循环来创建新列。 您能否对这一声明进行更多解释?
Formula( :"parameter1[Type]"n * :parameter1 )
我正在考虑编写一个这样的 for 循环:
</CODE></PRE><PRE class="lia-code-sample language-markup"><CODE>colnames = dataDT << Get Column Names();
nc = ncols(dataDT);
DT = New Table("normalized", New Column("ID", values(dataDT:ID << get values)),
New Column("Type", values(dataDT:Type << get values)));
For(i = 3, i<= nc, i++,
DT << New Column( char( colnames[3]), Numeric, "Continuous", Format( "Best", 12 ), Formula( XXXX ) ));但我不知道如何正确构建公式。 它一直给我错误。 你能帮助我吗?
谢谢。
回复:如何将两个表相乘如果您不需要公式,您可以考虑矩阵的元素乘法,这可能会或可能不会“更好”。 在我的 MacBook 上,下面的代码大约需要 15 秒。
NamesDefaultToHere(1);
nr = 10000; // Number of rows
nc = 10000; // Number of Columns
dt1 = AsTable(J(nr, nc, RandomInteger(1, 20)));
dt2 = AsTable(J(nr, nc, RandomUniform(0, 1)));
m1 = dt1 << getAsMatrix;
m2 = dt2 << getAsMatrix;
dtFinal = AsTable(m1 :*</img> m2);
回复:如何将两个表相乘您可以使用虚拟联接和公式列。
Virtual join adds the blue and gold keysVirtual join adds the blue and gold keys虚拟加入添加了蓝色和金色钥匙
您可以交互地或使用 JSL 链接它们。
这可能使用 JMP16 名称:"参数3[类型]"n句法;你可能需要名字( “参数3[类型]” ) 反而。
// make example tables. **save them** so virtual join works.
factorDT = New Table( "Imported Data 2",
New Column( "Type", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2] ) ),
New Column( "parameter1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1.1, 1.2] ) ),
New Column( "parameter2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0.8, 0.9] ) ),
New Column( "parameter3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1.1, 0.9] ) )
);
factorDT << save( "$temp/factor.jmp" );
dataDT = New Table( "Imported Data",
New Column( "ID", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
New Column( "Type", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 1, 2, 2] ) ),
New Column( "parameter1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
New Column( "parameter2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 3, 2, 1] ) ),
New Column( "parameter3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3, 3, 2] ) )
);
dataDT << save( "$temp/data.jmp" );
// join the tables
factorDT:type << Set Property( "Link ID", 1 );
dataDT:type << Set Property( "Link Reference", Reference Table( "factor.jmp" ) );
// add formula columns
dataDT << New Column( "p 1", Numeric, "Continuous", Format( "Best", 12 ), Formula( :"parameter1[Type]"n * :parameter1 ) );
dataDT << New Column( "p 2", Numeric, "Continuous", Format( "Best", 12 ), Formula( :"parameter2[Type]"n * :parameter2 ) );
dataDT << New Column( "p 3", Numeric, "Continuous", Format( "Best", 12 ), Formula( :"parameter3[Type]"n * :parameter3 ) );
// force the evaluation to complete
dataDT<<RUNFORMULAS></RUNFORMULAS>