# Tag Info

2

I have uploaded your table.txt to a code sharing server. This is exactly like the data should look on your disk. As already mentioned in several comments, you just have to import it as "Table" and everything is fine: data = Import["http://hastebin.com/raw/cudesisezu", "Table"]; data[[2]] (* {0, 0.997046, -4.00611*10^-6, -0.00442103, 0.299956, 0, ...

3

I think what you want can be probably be done with $PreRead, similarly to How to print unevaluated arguments in the form they were originally typed in? which I proposed as a possible duplicate. (If you need modified behavior for one particular Cell but not others see also CellEvaluationFunction). In that answer I gave code that fairly robustly lets a ... 2 Reading your comment about not wanting your TA's to type the quotes of a string, you could build some sort of user interface. Here's a very crude one. list = {}; DynamicModule[{f = ""}, Column[{ InputField[Dynamic[f], String], Dynamic[If[f =!= "", AppendTo[list, f]; f = ""]; list] }] ] 2 Aside from the fun evaluation control and numerical precision discussions happening, is this useful to accomplish the task you wanted? It does simply use string patterns to drop the appropriate zeroes. sigfigs[str_String] : = StringLength @ If[ StringContainsQ[s, "."], StringTrim[ StringReplace[s, "." -> ""], ... 6 I think you'll find this considerably faster... Intersection @@ (DictionaryLookup["*" <> # <> "*"] & /@Characters["aeiouy"]) and getting sneaky with letter probabilities, about five times as fast as above: Fold[Pick[#, StringFreeQ[#, #2], False] &, DictionaryLookup["*" <> First@Characters["yuioae"] <> "*"], ... 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, ... 1 How about: Cases[DictionaryLookup["*"], x_ /; SubsetQ[Characters[x], {"a", "e", "i", "o", "u", "y"}]] 5 One way to do this using Mathematica's native string patterns is like this: StringReplace["aaabccccc", xs:((x:WordCharacter)..) :> StringPadRight[x, StringLength@xs, "x"] ] (* "axxbcxxxx" *) Here is the same replacement expressed using a RegularExpression: StringReplace["aaabccccc", RegularExpression["((\\w)\\2+)"] :> StringPadRight["$2", ...

5

Using Regexes: StringReplace["aaabccccc", RegularExpression["(\\w)(\\1+)"] :> StringJoin["$1", Array["x" &, StringLength@"$2"]]] (* "axxbcxxxx" *)

1

As a recurrence: ComputePoly[{}] := 1; ComputePoly[{0}] := x1 ComputePoly[{1}] := x2 ComputePoly[l_List] := ComputePoly[l[[1 ;; 1]]]*ComputePoly[Rest@l] ComputePoly[{0, 1, 0, 1, 1, 1, 1}] (* x1^2 x2^5 *) Of course different recurrence relationships need different implementations. As you don't mention your actual one it's very difficult to provide more ...

1

This is very similar to a common problem that many symbolic Mathematica functions share, e.g.: Solve[2*x-5==15,x] and as can be seen from the example the standard way to solve that is to pass such symbols which are to be used as formal symbols as extra argument(s). As you guessed in your comment the most direct way to implement that would be something ...

3

You can directly match specific operators as: s = "abc\[CircleTimes]def" StringReplace[s, "\[CircleTimes]" -> "CircleTimes"] "abcCircleTimesdef" It seems not too unreasonable to manually create a list of all the operators you need to handle. this builds a list of rules for every possible "\[..]" character allspecial = (#[[1]] -> ...

2

This worked: StringReplace[ToString@FullForm@"\[CircleTimes]", ("\\[" ~~ Shortest[c__] ~~ "]") :> c] but there's a drawback - FullForm changes the string also in other places, for instance where a slash "\" exists, so another solution would be welcomed...

1

ClearAll[BigStringExpr]; BigStringExpr = (StartOfString ~~ anInteger : (Except["0", DigitCharacter] ~~ DigitCharacter ...) ~~ EndOfString :> ToExpression@anInteger) StringCases["1234", BigStringExpr] Head[%[[1]]] {1234} Integer

4

The given above answer is correct, however if you are not against using undocumented functions, then InternalStringToDouble["9.0E-03"] is much faster. To demonstrate the speedup, first generate some fake data heads = ToString /@ RandomReal[{1.0000, 9.9999}, 100000, WorkingPrecision -> 5] // Quiet; exp = ConstantArray["E-", 100000]; tails = ...

0

You can use NumberForm to customize the output. Something like the following should give you what you're after: d0Form[precision_:10] := NumberForm[#, precision, NumberFormat -> (If[(#3 == ""), Row[{#1, "d0", #3}], Row[{#1, "d", #3}]] &)] &}; Here's a test on a small matrix: matr = Table[RandomInteger[{0, 10^5}], {i, 2}, {j, ...

0

It seems that for some reason all Integer values are converted to Real in the environment in which the autoload process takes place, therefore the value of \$SystemWordLength is changed to a Real which breaks the path. I have been unable to figure out the source of the Integer to Real conversion and therefore I do not know what else it may affect, but I can ...

10

If I understand correctly, the closest to Python's triple quotes is a TextCell. You can enter it as follows: Here I opened an inline cell after typing the input a =. This is done by pressing Ctrl-9 (or going to the Insert menu, then to Typesetting... and Start Inline Cell). In the light orange highlighted box, you can type any text you want in a natural ...

3

Confirmed by WRI (@ilian) as bug introduced in 10.1.

6

To achieve customized display forms, you use either Format or MakeBoxes. Converting to string is usually a measure of last resort, and not what I would recommend here. Instead, just do this: expr = a.b + II (* ==> II + a.b *) II /: MakeBoxes[II, StandardForm] := RowBox[{"I"}] expr = a.b + II (* ==> I + a.b *) Edit: TraditionalForm, String ...

3

Since you are only doing this for printing then you can simply replace II with "I" Print[ToString[ReplaceAll[expr, II -> "I"] // TraditionalForm]] (* a.b + I *)

3

expr = a.b + II; II2I[n_] := StringReplace[ToString[n], "II" -> "I"]; II2I[expr]

6

URLDecode and URLEncode were introduced in Mathematica 10.0: url = "https%3A%2F%2Fwww.google.co.uk%2Fimages%2Fsrpr%2Flogo4w.png"; URLDecode[url] (*"https://www.google.co.uk/images/srpr/logo4w.png"*) The symbol definition can be accessed as follows, which is scarily close to @Guesswhoitis's code above. URLDecode[url]; Unprotect[URLDecode]; ...

0

This can also be done using operators. SetAttributes[DotEqual, HoldFirst]; DotEqual[a_Symbol, b_] := a = b@a; oStringJoin[h_] := Function[expr, StringJoin[expr, h], HoldAll]; myString = "some words "; myString \[DotEqual] oStringJoin@"more words"; myString (* "some words more words" *) Such an approach is general in the sense that can it be used ...

8

Even though belisarius' answer is probably closest to what you want, I find that I quite often do something like this: SetAttributes[sj,HoldFirst]; sj[x_Symbol, y__] := (x = StringJoin[x, y]) Now we can type myString = "some words "; sj[myString, "more words"]; myString (* "some words more words" *) That is, instead of using infix notation lhs ...

3

I am not sure if this is the best method, but I found this article which describes mathematica operators without predefined definitions. I used one to associate a function with the TildeTilde symbol, made by pressing esc+~+~+esc. SetAttributes[TildeTilde, HoldFirst] TildeTilde[a_Symbol, b_String] := (a = a <> b) You need to use HoldFirst attribute ...

6

Define your own: << Notation Notation[DoubleLongLeftRightArrow[ ParsedBoxWrapper[ RowBox[List["x_", " ", "⊕", " ", "y_", " "]]], ParsedBoxWrapper[ RowBox[List[" ", RowBox[List["x_", "=", RowBox[List["x_", "<>", "y_"]]]]]]]]] x = "caca"; x⊕"test"; x (*"cacatest"*) Edit Using the Notation palette you should see

0

There is a v10 function that simplifies this process dramatically: TextString. It has several options for specifying how different constructs are formatted. In this case, you are looking for ListFormat, e.g. ListFormat -> {"[", ",", "]"} Unfortunately, it does not have an option for changing a strings format, so we have to improvise. The docs use an ...

8

You can't use non-numeric data for EmpiricalDistribution (at least up to V9, and I saw nothing when I had 10.x installed that said otherwise). Deal with it as character codes: gc = ToCharacterCode@ToLowerCase@gettys; p3 = Partition[gc, 3, 1]; d = EmpiricalDistribution@p3; Probability[{a, b, c} == ToCharacterCode@"the" \[Conditioned] {a, b} == ...

Top 50 recent answers are included