Tag Info

Hot answers tagged

12

Original question As noted in the comments the use of Dispatch is the easiest way to make this replacement operation much faster. However taking this as an opportunity to explore other optimizations here are some examples for you to consider: (dsp = Dispatch[soln]) // RepeatedTiming // First 0.0030 Total[vars] /. dsp // RepeatedTiming {0.0038, ...


11

Approach As halirutan suggested in question 71310 we can create a custom, compiled color function and apply it using the trick Image[colorFunction@ImageData@img] on my computer with my custom avocado color function this is more than eight times faster than Colorize, taking only 0.035 seconds. How to create a fast custom color function In order to ...


7

It is also pretty straightforward to create your own color map. For example, the following code reads in the image, and multiplies each of the color channels by an appropriate factor, then recombines the three into a single color image. It is very fast. Change the constants (in this case, 0, 1, and 0) at will. img = ...


6

The OP's (current) definition of ncalc is unreadable and unsalvageable, so I made one up from pieces of the code. ncalc = Piecewise[{ {-21. + 294. u - 1029. u^2, u < 1/7}, {2. v (131.25 - 367.5 u + 257.25 u^2), 5/7 < u < 6/7}, {5.25, u == 6/7}, {33.8811 v^2 , u > 1/7}}, -1380.75 + 3160.5 u - 1800.75 u^2] When you set shared ...


4

Using the option Evaluated->True or wrapping the first argument of Plot with Evaluated gives a 100x speed-up: ls1[t_] := Quantity[10, "Nanometers"]/t Plot[ls1[Quantity[t, "Seconds"]]/Quantity[1, "SpeedOfLight"], {t, 0, 10}] // Timing ls2[t_] := Quantity[10, "Nanometers"]/t Plot[ls2[Quantity[t, "Seconds"]]/Quantity[1, "SpeedOfLight"], {t, 0, 10}, ...


1

In version 10 even a single Rule will produce a Dispatch object: Dispatch[ a -> 1 ] // InputForm Dispatch[{a -> 1}] Dispatch[ a -> 1 ] // AtomQ True Association is also a hash structure and provides a comparably fast alternative to Dispatch, which an interface for adding, deleting and updating rules. In many cases Associations may be ...



Only top voted, non community-wiki answers of a minimum length are eligible