Tag Info

Hot answers tagged

6

First, the old Random function uses an inferior PRN generator and should not be used other than for legacy compatibility, if I recall correctly. On my machine (version 7, Windows 7) the second method is faster than the first, though not by a great amount: 4.*Mean@Table[Boole[RandomReal[]^2 + RandomReal[]^2 < 1], {10^6}] // AbsoluteTiming With[{n = ...


5

One option is to use MapThread, which gets you there: List /@ MapThread[Plus, u v f] But the infix notation for the Dot product is more elegant (as J.M. proposed in the comment above): List /@ (f.(u v)) Note that if you're doing a lot of these computations, that f.(u v) has a very slight computational edge, which you can test with the Timing command: ...


4

If the problem is that the transformation function is slow to compute, a simple way to create and use a look-up table is to memoize the function: (* create an example image *) image = RandomImage[1, {30, 20}, ColorSpace -> "RGB"] ~ ImageResize ~ Scaled[10] (* define the transformation function with memoization *) mem : func[{x_, y_}] := mem = {x + 0.01 ...


3

ImageTransformation works with functions, not tables. It should be straightforward to define a function that carries out the same transformation as the table, but you will need to be aware that the #[[1]] and #[[2]] arguments go from 0 to 1 (across the image) so you will need to design the function to handle this input range. For example, you might want a ...


2

I think you have to make sure that your transformation function always handles input cleanly. Here's a test you can do to see what goes into your function. (And I think you can use real coordinates if you use the DataRange option.) i = ImageResize[ExampleData[{"TestImage", "Mandrill"}], {20, 20}]; The function: f[pt_] := (Print[pt]; {pt[[1]], pt[[2]]}); ...


2

Your original function can be written much more concisely using ArrayPad: f2[list_, p : {_, _}] := Partition[list ~ArrayPad~ p, Tr@p + 1, 1] f2[Range@5, {1, 3}] Also, since this question is tagged performance-tuning I would like to point out that using the zero-padding might be more efficient. A raw demonstration, using MinHsuan Peng's function to ...



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