将多个列表项连接在一起使用 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