Hot answers tagged

6

With the ability to connect to Python I found this snippet of code helpful. It imports a STATA .dta file using pandas and then outputs it as a Wolfram Dataset. importDTAMP[fileName_] := Module[{}, python37 = StartExternalSession[<|"System" -> "Python", "Version" -> "3.7.3"|>]; ...


3

Something like this should work. dims = Prepend[(Dimensions /@ bndrs)[[All, 2]], Dimensions[bndrs[[1]]][[1]]]; file = OpenWrite["a.txt"]; WriteString[file, ExportString[{dims}, "Table"]]; Do[ WriteString[file, "\n\n"]; WriteString[ file, ExportString[ Join[A["NonzeroPositions"], Partition[A["...


2

There are a number of issues that must be addressed. The AddToClassPath call should reference the directory or JAR file containing the compiled Java classes, not the source file. Since you are using NetBeans, the class files are normally compiled into the subfolder build\classes within the project folder (or possibly just build depending on the NetBeans ...


2

One way to do it is str = Import["file.dat", "Text"]; data = StringCases[str, "string 1\n" ~~ x___ ~~ "\nstring 2" :> ImportString[x, "Table"]] This example includes the newline character explicitly. You may or may not want to include one before the first "string" and after the "2"...


1

I am not certain whether your folder management is the best for what you want, but I can try to give you a working example that you can then modify to suit your needs. By no means does the code need to be as verbose as mine, but I only did it for the sake of clarity. Also the reason I am specifically using the 'chopped' string of the file is because when you ...


1

There are many ways of doing this. The fastest I can think of is Partition[Normal@BaseDecode[str], 2].{1, 256} which takes less than half of the time that ImportString requires. Timing comparisons: A = RandomInteger[255, 10^8] // ByteArray; S = BaseEncode[A]; C1 = Partition[Normal@BaseDecode[S], 2].{1, 256}; // AbsoluteTiming // First (* 4.11495 *) ...


1

We can use ImportString to decode the Base64 string and interpret the resulting bytes in a single step: ImportString["8ynnKdsp", {"Base64", "UnsignedInteger16"}, ByteOrdering -> -1] (* {10739, 10727, 10715} *) Explanation The documentation for the Base64 import format tells us: The import format and file encoding can be ...


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