Tag Info

New answers tagged

6

Another solution would be to use SemanticImportString (new in 10). Borrowing some code from Mr.Wizard so that I can compare my solution to his: strings = ToString @ Row[RandomChoice /@ {{"-", ""}, {#}, {"e"}, {"-", ""}, Range@12}] & /@ RandomReal[{0, 10}, 15000]; Needs["GeneralUtilities`"] Internal`StringToDouble /@ strings // AccurateTiming ...


1

There doesn't be to be a way to Import the colours. The only available information are the following: {#, Import["~/test.col", #]} & /@ Import["~/test.col", "Elements"] Thus you indeed need to Import your Graph from the .col file and add the colours afterwards: g = Import@"~/test.col"; data = Import["~/test.col", "List"]; vclist = ToExpression ...


0

why not modifying the data originally before exporting it. you may do something like this: data2 = List @@ data /. Rule -> Sequence /. Times -> List; sub = Join[{data2[[1]]}, data2[[2 ;; -2, 2]]]; numb = Join[data2[[2 ;; -2, 1]], {data2[[-1]]}]; and now if you want to export the data as list you can do it like this: ...


2

At this point I think it is probably best to import your data as a plain string and then extract your Rules using StringCases: text = Import["odd.dat", "Text"]; StringCases[text, x : Shortest["Subscript[" ~~ __ ~~ "] -> " ~~ NumberString] :> ToExpression[x]] {Subscript[a, 1, 1] -> -39.0704, Subscript[a, 1, 2] -> 32.8391, Subscript[a, 1, ...


2

First I saved the data in a file named "data.dat" as Text, then I imported your data, including the Delta data = Import[...] then the trick: data // ToExpression and here are the data {{1.171937359784618*10^6}, {Subscript[a, 1, 1] -> -39.07037581001687, Subscript[a, 1, 2] -> 32.83913739257574, Subscript[a, 1, 3] -> 47.04859760352587, ...


2

The best way to export your data and import it again is to use the WDX data format. Wolfram Language Documentation Center - WDX Data Format It allows for platform independent storing and exchange of information and data. Example Export["solve.wdx", Solve[7 Subscript[a, 1, 1] + 5 Subscript[a, 1, 2] == 17 && 2 Subscript[a, 1, 1] + 3 ...


2

You can read in the expression using Get: << "/yourpath/sample.txt"; c = Classify[%] or alternate forms: c = Classify[ << "/yourpath/sample.txt"] c = Classify[Get["/yourpath/sample.txt"]]


1

Use ToString Do[ Export[yourPathToFile<>ToString[i+20]<>".csv", yourData[[i]]] ,{i,0,22}


10

In this case it would be far more reliable to request the information from the source directly. You can find the source using your web browser's developer tool, in Google Chrome you find this information under "Network." It should look something like: Importing that data as JSON gives us a nested list of rules containing all the data: rawData = ...


6

Update Inspired by Andy Ross header = First @ iris; header = StringReplace[header,"."->""](Because Dot is protected in Mathematica) data = Rest @ iris; assign[name_, value_] := Evaluate[ToExpression[name]] = value; Thread[ assign[header, Transpose@data] ] ==================================================================== If you ...


0

A very simple way to import tables of integers is like this: add a few columns in Excel containing the separators "{", "," and "}," in between your columns of integers: then paste in your workbook, and add a leading "{" and a trailing "}" and ... done. (mind the superfluous comma at the end). Works in version 10.


5

Version 10 introduced Interpreter which would seem suited to this task: Interpreter[form] represents an interpreter object that can be applied to a string to try to interpret it as an object of the specified form. Interpreter["Number"]["1.23e-5"] 0.0000123 Unfortunately it seems that like many new-in-10 functions this is far from optimized. ...


7

This is an ideal use case for SemanticImport, but unfortunately it has issues getting the commas right in version 10.0. Luckily, version 10.0.1 has already fixed this bug:


11

I worked on Interpreter. As far as the implentation is now, the DelimitedSequence parser does not support quoting, so what you want can't be done. We'll try to add it in a future version.


0

First, import the data: data = Import[SystemDialogInput["FileOpen"]]; The first line is just the column descriptions, so remove it: data = data[[2 ;; All]]; Each successive 17 elements is the CPU usage for CPU "all, 0, 1, ..., 15", so let's separate them by CPU: {all, zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, ...


2

Try constraining the execution time to something reasonable TimeConstrained[Import[filename, "Elements"], 1] this will abort the Import function after 1 second allowing you to skip the offending files. A list of non-offending files can be obtained with this: filelist = Select[FileNames["*.*"], (Length@TimeConstrained[Import[#, "Elements"], 1] > 0) ...


7

Steven, looking at the data you can see that you already have the latitude and longitude converted into de proper format under fields lng and lat. asamdataset[1] // Normal (*<|"Subregion" -> "57", "Reference" -> "2014-175", "Description" -> "GHANA:On 25 July, the 3,232 gross ton Kiribati-flagged product \ tanker MT HAI SOON 6 was boarded ...


0

Being fairly annoyed that mathematica can't do this straightforward thing..here is a solution using an external python script: Export["test.txt", Join[{StringJoin[Join[{"*"}, ConstantArray[" ", {80}], {"*"}]]}, RandomInteger[100, {3, 20}], {"end of file\n"}], "Table"] FilePrint["test.txt"] overwrite[file_, off_, string_] := Run[ ...


2

Low-level file operators like Write won't work here because OutputStreams (such as you get with OpenWrite and OpenAppend) can't have their StreamPosition set before the end of the file. In general overwriting characters in an existing file isn't terribly trivial; you can use c-functions likefile_ptr = fopen(file, "rb+") to do this, but you're overwriting ...


4

One workaround I found is this: getRand[] := AbortProtect@Module[{stream, res}, stream = OpenRead["!head -c 4 /dev/random", BinaryFormat -> True]; res = BinaryRead[stream, "UnsignedInteger32"]; Close[stream]; res ] Tested on OS X and Linux.


2

Here is an example of how you can fetch the results, but there is the question of what to do if multiple results are returned. I'm using URLBuild but you could do the same manually if you don't have Mathematica 10. num = 4.17 Cases[ Import[ URLBuild[ "http://isc.carma.newcastle.edu.au/advancedCalc", {"input" -> num}], "XMLObject"], ...


4

Only a suggestion, not a full answer: As far as I can see the ISC returns Maple code. Therefore, after importing the output of the website as string into Mathematica, the biggest challenge is to convert the output from Maple to Mathematica code. A quick google search reveals that there is a package in the MathLibrary. I guess chances are good that the ...



Top 50 recent answers are included