Simon Woods
Reputation
60,008
228/100 score
 Feb 14 comment GatherBy/SplitBy and Sort a list IMO the best thing would be to remove both updates from the question, and accept an answer which best addresses the problem as originally asked. Then create a new question about why two low-accuracy numbers can give True for a==b but False for N[a]==N[b]. Feb 14 comment GatherBy/SplitBy and Sort a list The issue of how N affects Accuracy is a quite different problem to the original question regarding efficient sort & gather algorithms. It should be a separate question. People took time and trouble to answer the original question, and it's rather unfair to claim that their (perfectly good) answers don't work because of special features in your data that you didn't reveal until several hours later. It will also be more useful to future visitors looking for efficient sort & gather algorithms if the question is unencumbered by the requirement to avoid using N. Feb 13 comment GatherBy/SplitBy and Sort a list Check those results with a calculator, they are wrong! Feb 13 comment GatherBy/SplitBy and Sort a list No, the norms are {0., 1.64012, 0.632456, 0.632456, 1.64012, 1.58114, 0.640312, 0.6, 1.6, 0.640312, 1.58114} Feb 13 comment GatherBy/SplitBy and Sort a list f7 is lovely. One of those bits of code that seems obvious, once someone else has thought of it... Feb 13 comment GatherBy/SplitBy and Sort a list I'm not sure why that's what you expect. For example {-0.5, 0.4} and {0.2, -0.6} have different norms, so why are you expecting them in the same sublist? Feb 13 comment GatherBy/SplitBy and Sort a list For the first one you need to take into account that GatherBy returns lists of points, so you need to apply Norm to the first element not the whole list, e.g. SortBy[GatherBy[list2, Norm], N[Norm[#[[1]]]] &] Feb 13 comment GatherBy/SplitBy and Sort a list Well GatherBy[SortBy[list2, N[Norm[#]] &], Norm] gives the correct answer unlike the typo version. Feb 13 comment GatherBy/SplitBy and Sort a list The difference between using Norm and #.#& accounts for a lot of the speed differences. It would be interesting to compare the different approaches using the same norm function throughout. Feb 13 comment GatherBy/SplitBy and Sort a list Regarding the update, you have a misplaced bracket. N[Norm[#] &] should be N[Norm[#]] & Feb 13 comment How to mix symbols and text for labels in manipulate? You have multiplied the subscript and the string, instead use Row to format expressions in a row, e.g. Row[{Subscript[φ, 0], "(degrees)"}] Feb 13 comment GatherBy/SplitBy and Sort a list I suggest using #.#& in place of N@*Norm for integers - it omits the square root step but that doesn't change the ordering. Feb 13 comment GatherBy/SplitBy and Sort a list I had result = With[{n = #.# &}, list~GatherBy~n~SortBy~n@*First] - same principle but faster if list is integers. Feb 13 comment How to count proportion of two phase in a electron microscope picture Do you have a version of the image without the text and arrows overlay? Feb 13 comment Slow and laggy animation of an electromagnetic wave It animates pretty smoothly for me. Did you try just the arrows or just the curves, to see if either one in particular is causing the problem? Feb 12 comment Plotting a two lists generated after running a for loop You'll need to give a more detailed description of what the code is supposed to be doing, the code itself is rather strange and it's difficult to interpret the intention. Feb 10 comment How to visualize .data files? According to this the MITgcm .data files contain binary data. You can read them with BinaryRead, though you will need to understand the file format to interpret the data properly. According to that link there are matlab scripts included with MITgcm which read the output files. You could examine those scripts and write a Mathematica version. Feb 8 comment I want to compute the derivative of Black and Scholes option Don't use underscores in variable names, don't use built-in symbols like Value as variable names, use Rule (entered as ->) not RightArrow for rules. Feb 6 comment Evaluation of Alternatives Great answer. This kind of insight from the inside is really valuable to those of us trying to understand the system from the outside! IMO it would be a good idea to include this inconsistency as a "Possible Issue" in the documentation for Flat or Alternatives. Feb 6 comment Why a part of this expression, similar to another, is left unchanged? A simpler example is a + b + c + d /. {a + b -> 1, c + d -> 2}