將多個清單項目連接在一起使用 JMP12.2 - 我正在尋找一種快速方法,以 1 對 1 的方式將兩個不同列表中的列表項目連接在一起 - 假設列表具有相同數量的項目。 這將用於非常大的表中的每一行 - 所以如果可能的話,我不喜歡迭代函數。
這是我想要實現的目標的範例:
list1 = {"a","b","c","d","e","f","g"};
list2 = {"1","2","3","4","5","6","7"};
可接受的結果可以是字串或列表。 如果字串由分隔符號分隔。
列表結果:{"a,1","b,2","c,3","d,4","e,5","f,6","g,7"};
字串結果:「a:1,b:2,c:3,d:4,e:5,f:6,g:7」;
大規模客製化回覆:將多個清單項目連接在一起我把事情搞砸了! 以下是可能在舊版的 JMP 中正常運作的更新版本:
dtGraph = New Table( "stats",
Add Rows( 0 ),
New Column( "size", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
New Column( "table time", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
New Column( "loop time", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) )
);
For( n = 1, n < 1e7, n *= 2,
dtGraph << addrows( 1 );
dtGraph:size[N Rows( dtGraph )] = n * 3;// 3 items repeated...
list1 = Repeat( {"a", "b", "c"}, n );
list2 = Repeat( {"1", "2", "3"}, n );
start = HP Time(); // data table method begins here
dt = New Table( "temp",
New Column( "a", Character, "Nominal", Set Values( list1 ) ),
New Column( "b", Character, "Nominal", Set Values( list2 ) ),
New Column( "c", Character, "Nominal", formula( a || ":" || b ) ),
invisible
);
dt << runformulas;
result = dt:c << getvalues;
Close( dt, nosave );
stop = HP Time(); // data table method ends here
Show( stop - start );
result = Concat Items( result, "," );
Show( Length( result ), Left( result, 100 ) );
dtGraph:table time[N Rows( dtGraph )] = (stop - start) / 1e6;
result = {};
start = HP Time(); // loop method begins here
While(
aa = Remove From( list1, 1 );
bb = Remove From( list2, 1 );
N Items( aa ); // as long as something was removed...
, // do this...
Insert Into( result, aa[1] || ":" || bb[1], 1 ) // <<<<<<<<< here
);
result=reverse(result); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< and here
stop = HP Time(); // loop method ends here
Show( stop - start );
result = Concat Items( result, "," );
Show( Length( result ), Left( result, 100 ) );
dtGraph:loop time[N Rows( dtGraph )] = (stop - start) / 1e6;
Wait( 1 );
);
dtGraph << Graph Builder(
Size( 1200, 500 ),
Show Control Panel( 0 ),
Variables( X( :size ), Y( :table time ), Y( :loop time, Position( 1 ) ) ),
Elements( Points( X, Y( 1 ), Y( 2 ), Legend( 5 ) ), Smoother( X, Y( 1 ), Y( 2 ), Legend( 6 ) ) ),
SendToReport(
Dispatch( {}, "size", ScaleBox, {Scale( "Log" ), Inc( 1 ), Minor Ticks( 1 )} ),
Dispatch( {}, "table time", ScaleBox, {Scale( "Log" ), Format( "Best", 12 ), Inc( 1 ), Minor Ticks( 1 )} )
)
);看快速列表尋求解釋;我專注於 RemoveFrom 函數,而忘記了 Insert Into 函數。
Insert Into needs a 3rd argument to insert at the beginning of the list, and then a reverse when done.Insert Into needs a 3rd argument to insert at the beginning of the list, and then a reverse when done.Insert Into 需要第三個參數來插入到清單的開頭,然後在完成後反向插入。
我還重命名了循環中的變量,這樣它們就不會使用資料表列作為臨時變量。
回覆:將多個清單項目連接在一起我的問題已解決 - 這對您和其他可能覺得有用的人來說更多是僅供參考。
我確實可以訪問 JMP14.3,但該腳本需要在 JMP12.2 上運行才能在我的組織內相容。
我嘗試了您的分析,對於 JMP14.3 得到了與您類似的結果 - 可能在計算能力上存在一些差異。

然而,JMP12.2 循環的性能完全不合規矩。 我必須在 98304 之後終止 JMP.exe 進程,因為時間呈指數級增長,並且永遠不會到達第 24 行:

回覆:將多個清單項目連接在一起謝謝你,這很好用。 儘管它使用迭代函數,但它具有良好的性能。
回覆:將多個清單項目連接在一起是的,我可能一直假設迭代(對於每一行)中的迭代(for)會嚴重影響腳本效能,但是在建置範例之後@SDF1表示性能出奇的好。
感謝您的比較 - 我本來認為 C++ 總是會更快,但表總是有更多的開銷是有道理的。 我想知道“開始資料更新”和/或“私有”表會改善表開銷嗎?
回覆:將多個清單項目連接在一起JSL 循環有著不應有的壞名聲。 如果循環的內部做了很多工作,那麼循環的開銷通常就不那麼重要了。 任何沒有 JSL 循環的解決方案都會在其他地方涉及一個循環,也許在 C++ 中,這會更快一點,但仍然如此。 不管怎樣,這裡對兩種方法進行了比較,一種涉及 JSL 循環,另一種使用隱藏在 JMP 的 C++ 程式碼中的循環。
Graph showing crossover times of the two algorithms at around 39,000 elements.Graph showing crossover times of the two algorithms at around 39,000 elements.該圖顯示了兩種演算法在大約 39,000 個元素處的交叉時間。
dtGraph = New Table( "stats",
Add Rows( 0 ),
New Column( "size", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
New Column( "table time", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
New Column( "loop time", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) )
);
For( n = 1, n < 1e7, n *= 2,
dtGraph << addrows( 1 );
dtGraph:size[N Rows( dtGraph )] = n * 3;// 3 items repeated...
list1 = Repeat( {"a", "b", "c"}, n );
list2 = Repeat( {"1", "2", "3"}, n );
start = HP Time(); // data table method begins here
dt = New Table( "temp",
New Column( "a", Character, "Nominal", Set Values( list1 ) ),
New Column( "b", Character, "Nominal", Set Values( list2 ) ),
New Column( "c", Character, "Nominal", formula( a || ":" || b ) ),
invisible
);
dt << runformulas;
result = dt:c << getvalues;
Close( dt, nosave );
stop = HP Time(); // data table method ends here
Show( stop - start );
result = Concat Items( result, "," );
Show( Length( result ), Left( result, 100 ) );
dtGraph:table time[N Rows( dtGraph )] = (stop - start) / 1e6;
result = {};
start = HP Time(); // loop method begins here
While(
a = Remove From( list1, 1 );
b = Remove From( list2, 1 );
N Items( a ); // as long as something was removed...
, // do this...
Insert Into( result, a[1] || ":" || b[1] )
);
stop = HP Time(); // loop method ends here
Show( stop - start );
result = Concat Items( result, "," );
Show( Length( result ), Left( result, 100 ) );
dtGraph:loop time[N Rows( dtGraph )] = (stop - start) / 1e6;
Wait( 1 );
);
dtGraph << Graph Builder(
Size( 1200, 500 ),
Show Control Panel( 0 ),
Variables( X( :size ), Y( :table time ), Y( :loop time, Position( 1 ) ) ),
Elements( Points( X, Y( 1 ), Y( 2 ), Legend( 5 ) ), Smoother( X, Y( 1 ), Y( 2 ), Legend( 6 ) ) ),
SendToReport(
Dispatch( {}, "size", ScaleBox, {Scale( "Log" ), Inc( 1 ), Minor Ticks( 1 )} ),
Dispatch( {}, "table time", ScaleBox, {Scale( "Log" ), Format( "Best", 12 ), Inc( 1 ), Minor Ticks( 1 )} )
)
);JMP 14 是我能接觸到的最舊的。 我認為循環演算法在 JMP 12 中也會有類似的效能。 它在處理這兩個清單時有意破壞它們,因為較舊的 JMP 版本在清單中沒有快速索引,但刪除第一個元素的速度很快。 資料表演算法首先進入循環,因此它可以在列表被銷毀之前使用它們。
回顧 JSL,我不應該聲稱任何一種演算法更簡單或更容易遵循。
回覆:將多個清單項目連接在一起你好@ts2 ,
根據您想要對結果執行的操作,您可以採用幾種不同的方式來處理它。 我知道您不想執行迭代函數,但為了獲得正確的輸出(其中一個列表的元素連接到另一個列表的元素),我認為您必須執行 For 循環。 您也可以考慮做一個關聯數組。
以下是一些可能幫助您開始解決方案的 JSL。
names default to here(1);
list1 = {"a","b","c","d","e","f","g"};
list2 = {"1","2","3","4","5","6","7"};
AA = Associative Array(List1, List2);
i=.;
result1={};
For(i=1, i<=nitems(list1), i++,
result1[i]=list1[i]||":"||list2[i]
);
result 2 = EvalList({Concat Items(result1, ", ")});
Show(result1);
Show(result2);
Show (AA);希望這可以幫助!,
DS