Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
27

While trying to debug this issue myself, I stumbled across Todd Gayley's name in the source of one of the documentation .m files and contacted him directly. Todd was super great to work with---and at the end of an hour of screensharing he provided an easy workaround. The workaround essentially short-circuits one tiny feature of a normal documentation search....


15

But I would like to know the positions of "Element 1" and "Element 2"... You can still use Position[]; things are a little more elaborate, though, due to the strings: Position[list, s_String /; StringMatchQ[s, "El*"]] {{4}, {7}} Extract[list, %] {"Element 1", "Element 2"}


14

This is from Wolfram technical support: De-select Help > Internet Connectivity > "Allow Mathematica to access the Internet" and then try using the Documentation Center. If this fixes the hang then have them allow internet connectivity again and test the Documentation Center again. Finally, setting my proxy settings to "Direct connection to the ...


14

For large lists, this should be snappy: Pick[Range@Length@dat, StringTake[dat, UpTo@4], "star"] and actually, taking advantage of listability, Pick[Range@Length@dat, StringMatchQ[dat, "star*"]] is a bit faster it seems...


13

SeedRandom[42]; haystack = RandomReal[1, 6300]; AbsoluteTiming[ f = Nearest[haystack -> Range@Length@haystack]; {f[.3, 1], haystack[[f[.3, 1]]]}] (* -> {0.015625, {{3123}, {0.300033}}} *) Of course in this case most of the time is expended calculating the nearest function. If your points aren't changing from one use to the next, the time for ...


13

One can also go about this using integer linear programming, with an array of 0-1 variables indexed by vertices and colors. Here is one encoding of that approach. constrainedColorings2[graph[vertices_, nbrhds_], colors_List, start_List, v_] := Module[ {unassigned, nv = Length[vertices], nc = Length[colors], vars, fvars, c1, c2, c3, c4, pos1, pos2, ...


12

Here is a way to search from within mathematica: notebooks = Quiet@FileNames["*.nb", NotebookDirectory[], 2]; Monitor[Select[ Table[{nb, StringJoin@Select[ StringSplit[Import[nb, "Plaintext"], "\n"] , ((If[#, Print["match on:", nb]]; #) &@ StringMatchQ[#, "*NIntegrate*"]) &, 5]}, {nb,notebooks}], #[[2]] !...


11

After looking better into the comment by Szabolcs, I have chosen this path (which I did try for images, but it didn't cross my mind to use it for web): result = Import[ "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=furry%20beasts", "JSON"] and then "url" /. ("results" /. ("responseData" /. result)) to get the links to the pages. Or, ...


11

Here's a tiny utility function you might use if you're trying to look for a message that contains a known string: searchMessages[str_String, opts___] := Sort[Select[ Flatten[Map[ToExpression[#, InputForm, Defer] :> Evaluate[ToExpression[#]] &, StringCases[FindList[$InstallationDirectory <> "/...


11

Position[dat, _String?(StringMatchQ[#, "star" ~~ ___] &)] or Position[dat, _String?(StringMatchQ[#, "star*"] &)] or Position[dat, _?(StringMatchQ[#, "star*"] &), Heads -> False] or Position[StringMatchQ[dat, "star*"], True] (*thanks: @TomD *) {{1}, {7}, {13}, {19}} Alternatively, Pick[Range@Length@dat, StringMatchQ[#, "star*"] & ...


11

This seems to be a case for OrderlessPatternSequence tT = {{7, 1, 2}, {7, 2, 3}, {7, 3, 8}, {7, 1, 6}}; MemberQ[tT, {OrderlessPatternSequence[1, 2, 7]}] True Or define a function to wrap the second argument of MemberQ: foo = {OrderlessPatternSequence @@ ##}&; MemberQ[tT, foo @ {1,2,7}] True MemberQ[tT, foo @ #] & /@ {{1, 2, 7}, {3, 8, 7},{...


10

ruebenko provides the built-in function, but supposing FreeQ was not provided we can find another way. You are on the right track to use ReplaceAll, but it would be much better to give a result as soon as the search pattern is found. freeQ[expr_, pat_] := Catch[expr /. pat :> RuleCondition@Throw[False, "freeQ"]; True, "freeQ"] RuleCondition (1)(2)(3) ...


10

The functions you are looking for are MemberQ and FreeQ. Both functions take a levelspec and the Option Heads, but the default value for each is different. You can determine if expression x appears anywhere in a using: MemberQ[a, x, {0, -1}, Heads -> True] Or assuming the default option Heads -> True for FreeQ simply: ! FreeQ[a, x]


10

Update This code is no longer the most up-to-date. The properly up-to-date code is in the package on GitHub. For a run-down of the changes between this and that see the discussion between b3m2a1 and Nasser that starts here and the commit messages. The key here will be that all properly written documentation pages have a "Metadata" TaggingRule. Then we ...


9

I think this works correctly: ClearAll[min, doMin]; min[x_] := doMin[x] // Reap // Last // Flatten // Reverse // FromDigits; doMin[x_] := With[ {d = Range[9]^2}, If[ x > 81, Sow@ConstantArray[9, IntegerPart[x/81]]; doMin[Mod[x, 81]], Sow@Sqrt@Select[d, # >= x &, 1]]]; min[100] // AbsoluteTiming {0.001005, 59} min[...


9

DictionaryLookup for each case, combined with string patterns involving ___ can be very slow. It would be faster to do it in one pass over all the words in the dictionary: With[{words = DictionaryLookup[], letters = Characters["aeiouy"]}, Select[words, Intersection[Characters[#], letters] == letters &]] This takes ~0.35 seconds on my laptop, ...


9

strs = {"first block of text with random content", "different block of text", "1 2 3 4"}; Nearest[(StringPadRight[#, 50] & /@ strs), "content random with"] This is a deep and complex question apparently: Mathematica has a menagerie of built in goodies to assemble your own variant. EditDistance DamerauLevenshteinDistance ...


9

As of Mathematica 11: filenames = Table[CreateFile[], 3]; content = {"first block of text with random content", "different block of text", "1 2 3 4"}; MapThread[Put, {content, filenames}]; index = CreateSearchIndex[filenames]; Perform searches using TextSearch: Snippet /@ Normal@TextSearch[index, "block"] In order to rank search results, score them ...


9

If there is no particular reason for using Outer, then this is simple and straightforward: tab = Flatten[Table[{a, b, x, f[a, b, x]}, {a, -10, -1}, {b, 1, 10}, {x, 1, 10}], 2]; pos = Select[tab, #[[4]] > 0 &] Part (because Length @ pos = 100) of the output: {{-9, 10, 1, 1}, {-8, 9, 1, 1}, {-8, 10, 1, 2}, {-7, 8, 1, 1}, {-7, 9, 1, 2},...}


9

So it looks like the only real way to do this is by hacking the mainframe package that underlies this. Everything seems to be clumsy and hard coded, so I had to dig a little. The following works for Google, but it is easily adaptable to Bing. The main function of interest is GCSFormatRequestParameters which formats request parameters to Google Custom Search....


8

SeedRandom[1]; testMatrix = RandomInteger[10^4, {100, 4000}]; Position[testMatrix, x_ /; x >= 1000] // Hash // AbsoluteTiming Position[UnitStep[testMatrix - 1000], 1] // Hash // AbsoluteTiming Compile[{}, Position[UnitStep[testMatrix - 1000], 1]][] // Hash // AbsoluteTiming SparseArray[UnitStep[testMatrix - 1000]]["NonzeroPositions"] // Hash // ...


8

It seems I misunderstood the question. Here's an update, which is a considerable improvement, too. It relies on Implies[x, y] being equivalent to Boole[x] (1 - Boole[y]) == 0. falsePattern = Table[False, {15}, {15}]; truePattern = Table[True, {15}, {15}]; SeedRandom[1]; randomPattern = RandomChoice[{True, False}, {15, 15}]; impliesPosition[board_, ...


8

All three of parameters for FileNames can affect the depth at which Mathematica searches for results. It seems like your confusion is a result of interaction among these parameters. This is easily understandable as the documentation for FileNames is not very illustrative. (Indeed my first attempt at answering this question was faulty for the same reason.) ...


8

There is some built-in binary search code but not in the core language as far as I know. There is BinarySearch from the Combinatorica package, which is still the function I use most often despite the fact that that package is now deprecated and loading it causes shadowing of some Symbols. There is the undocumented GeometricFunctions`BinarySearch but this ...


8

I'd say that the acceptable forms of the query string are much more limited than the documentation lets on. In fairness though, TextSearch is marked [[Experimental]] in the docs, so it may very well be in a state of flux and you would probably not want to use it for anything critical. Having said that, some spelunking of the definition of TextSearch reveals ...


7

Mathematica now supports a native connection to GoogleCustomSearch API. You can do for example gs = ServiceConnect["GoogleCustomSearch"] gs["Search", {"Query" -> "Jennifer Lawrence"}] You can also use image search gs["Search",{"Query"-> "Jennifer Lawrence","SearchType"-> "Image"}] To use GoogleCustomSearch API you need an API Key and a Custom ...


7

String matching works a little better. Think of each row in the board as a string on the alphabet {"0", "1"}. The "pattern" is a set of instructions to look for particular configurations of "0" on the board, because a presence of a "1" in the pattern is no restriction at all and a "0" in the pattern means there must be a corresponding "0" on the board. ...


7

Here's a way to use Nearest: SeedRandom[1]; (* for reproducibility; omit in application *) list = Table[N@{a, b, RandomReal[]}, {a, 1, 100}, {b, 1, 100}]; flat = Flatten[list, 1]; nf = Nearest[flat[[All, 1 ;; 2]] -> flat] (* NearestFunction[{10000, 2}, <>] *) nf[{10.2, 5.1}] (* {{10., 5., 0.588169}} *) Note: I converted the OP's integer ...


7

In response to a), you can write Merge[Rule @@@ data, Identity], which is slightly simpler. In response to b), there are two different ways to do this nicely. One of which works in 10.0.0, the other will have to wait for 10.0.1. In 10.0.0 we can use GroupBy to associate each unique key with the set of corresponding values: grouped = GroupBy[data, First -&...


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