如何將兩個表相乘我有一個大數據表和一個標準化因子表。
數據表如下所示:
| 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>