Tag Info

New answers tagged

1

a 'loopless' one liner.. This takes ~5 minutes, way slower than the original, but considerably faster that Ronald's.. max = 5000; Clear[val, x, y, z, n] val[x_, y_, z_, n_] := 2 (2 n^2 + (y - 2) (z - 2) + x (y + z - 2) + 2 n (x + y + z - 3)); a = Normal@ SparseArray[Rule @@@ #, max] &@(val[x, y, z, n] /. FindInstance[ val[x, ...


3

This is an interesting, if (necessarily) ill-posed question. My approach is to couch it in more general terms and attempt to clarify what is possible, natural and generalizable by exploring the meaning of "clean", "efficient" and "non-contrived". Some implications for language design are also discussed. max = 5000; val := 2 (2 n^2 + (y - 2) (z - 2) + x (y ...


2

Leonid Shifrin's implementation of a trie can be used for this purpose. It is available both for lists and for associations. For associations: ClearAll[makeTreeAssoc]; makeTreeAssoc[wrds : {__String}] := Association@makeTreeAssoc[FileNameSplit /@ wrds]; makeTreeAssoc[wrds_ /; MemberQ[wrds, {}]] := makeTreeAssoc[DeleteCases[wrds, {}]]; makeTreeAssoc[wrds_] ...


3

First off, a more compact form of filesInDir: fileTree[f_, d_] /; DirectoryQ[f] && d > 0 := FileNameTake[f] -> (fileTree[#, d - 1] & /@ FileNames[___, f]) fileTree[f_, _] := FileNameTake[f] Example usage: fileTree[$UserBaseDirectory, 2] (* "Mathematica" -> {"ApplicationData" -> {"CCompilerDriver", "DeviceFramework", ...


1

Update: much simpler now. If this works right I think I would consider it superior. Update 2: I attempted to add specific handling of files and directories. Please tell me if this appears to work and produce a format that is acceptable to you. fn[x : {___, {_, __}, ___}] := Normal @ GroupBy[x, First -> Rest, fn] fn[x_List] := Join @@ x files = ...


1

One way to improve the performance of your code is to remove definitions of auxiliary functions from the bodies of function definitions. Such auxiliary functions are redefined every time the function is called. This is demonstrated by f[] := Module[{g}, g[] := SymbolName[g]; g[]] Table[f[], {4}] {"g$11401", "g$11402", "g$11403", "g$11404"} In your ...


0

This is similar, but perhaps a bit more readable than yours: exMag=Total@Map[ EFieldxComponent[#["alignType"], \[CurlyEpsilon]r, testPtx, testPty, testPtz, #["x1"], #["x2"], #["y1"], #["y2"], #["z1"], #["z2"], \[Rho]\[ScriptL]] &, activeSegments] alternately you might use the Dataset built in map functionality: ...


1

There may be better approaches, but this is what I found to work. I replaced: segmentMapEFieldx[testPtx_, testPty_, testPtz_, \[CurlyEpsilon]r_, \[Rho]\[ScriptL]_]:= Module[ {segmentIndex, segmentCount, exMag}, exMag = 0.0; segmentCount = Length[activeSegments]; For[segmentIndex = 1, segmentIndex<=segmentCount,segmentIndex+=1, ...


10

It depends what you want as result and please don't forget to search this site and look through other posts like this one: How can I add a column into a existing Dataset? Anyway, let me give you two simple examples: f = <|#, "x2" -> #x^2|> &; h = <|"Value" -> #x + #y + #z|> &; Map[f, testPoints] Map[h, testPoints] and you ...



Top 50 recent answers are included