Given a sorted list of numbers $S$, I want to create a function that accepts a list of numbers $L$ and for each number $l \in L$ it returns the index of the largest number $s \in S$ such that $s {0.405196, 4.56535, 7.04274, 7.95001, 8.6823} And, here are a couple examples of the argument to the function: {6.67917, 8.33874, 4.61316, 4.83263, 9.52033} {6.0669, 1.22425, 6.13959} Then, I want to create a function such that return: One possibility is to use: But, this approach is quite slow when dealing with large arguments: {1.15025, Null} I'm interested in arguments on the order of 10^6 elements, and ordered sets $S$ on the order 10^4 elements. Is there a faster method?SeedRandom[13];
S = Sort @ RandomReal[10, 5]SeedRandom[10];
list1 = RandomReal[10, 5]
list2 = RandomReal[10, 3]f:f = findIndices[S];f[list1]
f[list2](*
{2, 4, 2, 2, 5}
{2, 1, 2}
*)findIndices[s_] := Interpolation[
Thread[{s, Range@Length@s-1}],
InterpolationOrder->0,
"ExtrapolationHandler" -> {Evaluate[Length[s]]&, "WarningMessage" -> False}
]f = findIndices[S];
tst = RandomReal[{.5, 10}, 10^6];
f[tst]; //AbsoluteTiming
I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...
Comments
Post a Comment