Dictionary u将选择[list,UnitStep[list[[All,2]]]-3],1]添加到测试列表中。它不像其他的那么清晰,但是速度很快。 list = {{a, b, c, d}, {1, 2, 3, 4}, {5, 6, 7, 8}}; {5, 6, 7,
u将Dictionary u将选择[list,UnitStep[list[[All,2]]]-3],1]添加到测试列表中。它不像其他的那么清晰,但是速度很快。 list = {{a, b, c, d}, {1, 2, 3, 4}, {5, 6, 7, 8}}; {5, 6, 7,,dictionary,select,wolfram-mathematica,Dictionary,Select,Wolfram Mathematica,u将选择[list,UnitStep[list[[All,2]]]-3],1]添加到测试列表中。它不像其他的那么清晰,但是速度很快。 list = {{a, b, c, d}, {1, 2, 3, 4}, {5, 6, 7, 8}}; {5, 6, 7, 8} Select[#, # > 2 &] & /@ list[[2 ;;] Cases[list, x_List /; x[[2]] > 2] Cases[list, _List?(#[[2]] >
选择[list,UnitStep[list[[All,2]]]-3],1]
添加到测试列表中。它不像其他的那么清晰,但是速度很快。
list = {{a, b, c, d}, {1, 2, 3, 4}, {5, 6, 7, 8}};
{5, 6, 7, 8}
Select[#, # > 2 &] & /@ list[[2 ;;]
Cases[list, x_List /; x[[2]] > 2]
Cases[list, _List?(#[[2]] > 2 &)]
Cases[list, {_, x_, ___} /; x > 2]
Out[1] = {{5, 6, 7, 8}}
Cases[list, {x___} /; List[x][[2]] > 2]
Out[2] = {{5, 6, 7, 8}}
Select[list, #[[2]] > 3 &]
{{5, 6, 7, 8}}
In[45]:= Cases[list, {_, _?(# > 3 &), ___}]
Out[45]= {{5, 6, 7, 8}}
list = {{a, b, c, d}, {1, 2, 3, 4}, {5, 6, 7, 8}};
Pick[list, #>3& /@ list[[All, 2]] ]
selectByColumn[array_, index_, value_, range_] :=
Select[array, #[[index]] > value &][[All, range]]
solutions = Hold[
Select[list, #[[2]] > 3 &],
Cases[list, _List?(#[[2]] > 3 &)],
Cases[list, x_List /; x[[2]] > 3],
Cases[list, {_, x_, ___} /; x > 3],
Cases[list, {_, _?(# > 3 &), ___}],
Cases[list, {x___} /; List[x][[2]] > 3],
Pick[list, UnitStep[list[[All, 2]] - 3], 1],
Pick[list, # > 3 & /@ list[[All, 2]]]
];
testCases = Hold[
{"Packed Reals", RandomReal[{0, 5}, {dim, dim}]},
{"Unpacked Reals",
Developer`FromPackedArray@RandomReal[{0, 5}, {dim, dim}]},
{"Packed Integers", RandomInteger[{0, 5}, {dim, dim}]},
{"Unpacked Integers",
Developer`FromPackedArray@RandomInteger[{0, 5}, {dim, dim}]},
{"Rationals",
Rationalize[#, .001] & /@ RandomReal[{0, 5}, {dim, dim}]}
];
timing :=
Function[Null,
If[(time = First[Timing[Do[#;, {n}]]]) < .3,
Print["Too small timing for ", n, " iterations (dim=", dim,
") of ", HoldForm[#], ": ", time, " seconds!"]; time, time]/n,
HoldFirst];
generateTable :=
Labeled[TableForm[
Transpose@
Table[list = testCases[[i, 2]];
tmgs = List @@ (timing /@ solutions);
d = Last@MantissaExponent[Min[tmgs]] - 3;
Row[{Round[10^-d*#], ".\[Times]", Superscript[10, d]}] & /@
tmgs, {i, 1, Length[testCases]}],
TableHeadings -> {List @@ (HoldForm /@ solutions),
List @@ testCases[[All, 1]]}, TableAlignments -> Right],
Row[{"Average timings for ", dim, "\[Times]", dim, " list"}], Top]
Column[{dim = 5; n = 30000; generateTable, dim = 100; n = 3000;
generateTable, dim = 1000; n = 150; generateTable}, Left, 1,
Frame -> All, FrameStyle -> Gray]