Hot answers tagged

16

Your code is recalculating Mean[Hrank] and StandardDeviation[Hrank] with each comparison, making it extremely slow. Store them separately, and the calculation becomes much faster. I simulated an Hrank vector using: Hrank = RandomInteger[{0, 1000}, 200000]; And then did: mean = Mean[Hrank]; stddev = StandardDeviation[Hrank]; HighRank = Cases[Hrank, ...


14

The defect is known since March 2018. According to the support, it will be addressed in future versions (perhaps the next one - my guess). If you want to use the legacy converter: Import["fö.xlsx", {"DataLegacy"}] or Import["fö.xlsx", {"SheetsLegacy"}] For me, the new import functionality seemed to be better so I changed the paths & filenames ...


12

Since the page is generated asynchronously, you can use the same data source that the page itself does. Using the network inspector in my browser, I discovered that the page loaded its data from this url. It's some API that delivers JSON, so we can use that data. The first thing we can do is parse the URL, so get an idea of the various parameters we can ...


12

You might want to give the HDF5 format a try. It seems to be very efficient, even faster than MX in the example below. One has only to be careful to use the option "ComplexKeys" -> {"Re", "Im"} upon import (otherwise, each complex number is split into an association containing real and imginary part, rendering the method very inefficient). Export: n = ...


11

In version 11.3 for Windows you can do the following: In[1]:= file = URLSave["http://mirrors.standaloneinstaller.com/video-sample/ Panasonic_HDC_TM_700_P_50i.avi", "c:\\tmp\\sample.avi"]; In[2]:= Needs["MediaTools`"] In[3]:= MediaTools`Private`$MFInitReader[file] Out[3]= True In[4]:= AbsoluteTiming[i = MediaTools`Private`$MFReadNextFrame[];] Out[4]= {0....


11

Import as Table instead of CSV, and set the "FieldSeparators" option. ImportString[ "1;2 3;4", "Table", "FieldSeparators" -> {";"}] (* {{1, 2}, {3, 4}} *) "Table" is a generalization of CSV, TSV, etc. where you can customize the delimiters and separators.


10

If you write an HTML img tag like this: <img src="url/to/image.jpg"> then the image will be downloaded directly upon page load. Some frontend developers don't like this as they think it's more important to quickly show the bulk of the page. The images can come later. So what they did in this case was writing <img data-src="url/to/image.jpg"> ...


9

I found some tools which can translate python objects to wolfram expressions. https://github.com/WolframResearch/WolframClientForPython import pickle as pkl import wolframclient.serializers as wxf def pkl2wxf(path): file = open(path, 'rb') objs = [] while True: try : objs.append(pkl.load(file)) except EOFError : break file....


9

The short answer is that the following will work to import your file format as an array of numbers, which I think is your intention: Import[filename, {"Table", "Data", All, 1},"FieldSeparators" -> {"{", ",", "}"}] this uses the Import features to determine the field separaters to handle the braces and comma in your file content and the data elements to ...


7

You can actually start and control a web browser session from Mathematica using an experimental implementation for WebDriver, Since Mathematica 11.3. Look at this answer An example Module[ { session = StartExternalSession["WebDriver-Chrome"], iws, chromedo, img, links }, chromedo[cmd_] := ExternalEvaluate[session, cmd]; Pause[1]; iws = ...


7

I would suggest reading it with numpy and not Mathematica. It seems to me that this is not an exchange format. It is a format meant to be used only by numpy. Mathematica 12.0 has significantly improved ExternalEvaluate, and now you can transfer data from Python to Mathematica quite efficiently. ExternalEvaluate["Python", "import numpy as np x = np.arange(...


6

You could just save global variables and Subscript: Save[file, {"`*", "Subscript"}] If you really want to use the Notation package, then the problem is that the functions that know how to convert back and forth between the symbolized and unsymbolized forms are not being saved. Here are your definitions: Get["Notation`"] Symbolize[ParsedBoxWrapper[...


6

Image`ImportExportDump`ImageReadPNG[fileName] uses a cache. You should call Image`ImportExportDump`DeleteCachePNG[]. To improve the performance of Import you can use Import["file.png", IncludeMetaInformation->None].


6

It looks like this particular request requires you to set a header or two before it will respond the same way it does in the browser. In particular, it looks like it needs you to set the x-requested-by, Accept, and Referer headers. (I discovered this by simply whack-a-moling the headers to see which will give the correct response). I initially took the URL ...


6

You can solve this by importing "FullData" rather than "Data". dataA1 = Import[ "http://www.nuforc.org/webreports/ndxe201804.html", {"HTML", "FullData"}] dataA2 = Flatten[Most@Rest@dataA1[[8]], 1] dataA3 = Map[AssociationThread[dataA1[[8, 1, 1]], #] &, dataA2]; Dataset[dataA3] What's awkward about this is that there can be many empty tables that ...


6

str = Import["file.txt", "Data"]; mat = StringSplit[ StringReplace[str, {" " -> " {}", "e" -> "*^"}], WhitespaceCharacter .. ] // ToExpression; mat// MatrixForm


6

In 11.3 you can do: ExternalEvaluate[session, "JavascriptExecute" -> "return document.documentElement.outerHTML;"] In 12.0 and up, the syntax has change a little bit: session = StartWebSession[]; WebExecute[session, "OpenWebPage" -> "https://weather.com/weather/tenday/l/New+York+NY+10017:4:US"] html = WebExecute[ session, "JavascriptExecute"...


6

You just got to remove the initial data:image/jpeg;base64,, everything after that is base64 encoded pixel data. data = Import["https://pastebin.com/raw/KHE6A3gR", "Text"]; data = StringReplace[data, "data:image/jpeg;base64," -> ""]; ImportString[data, "Base64"]


5

updated based on comment feedback One more approach, using LibraryLink. Create a C file called strto.cpp as follows: #include <cstdlib> #include "WolframLibrary.h" EXTERN_C DLLEXPORT int wolfram_strtol(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) { char *string; mint base; mint result; string = ...


5

Import["twoLayers.pdf"] Double click on each graphics object separately and edit as you wish. While editing, order the objects by using the mouse right click, and Move to Front, Move to Back, etc. This will order them in the correct layer sequence. Double click on one graphics object first, hold the Shift key, and select the other graphics objects that you ...


5

Sorry, this is not possible in 11.3. Best bet for now is look at the ref/Format pages. We will look into ways to improve this in the future.


5

I can't tell you why this is occurring, but there are 4 lines which are each short by one number. You can see the line numbers below: 9850, 9900, 9950, 1000. diffusion = Import["diffusion.dat", "Table"]; (* save the import in case its needed later *) DumpSave["diffusion.mx", diffusion]; (* is it nxn? *) Dimensions@diffusion (* {10000} *) (* no, what ...


5

The easiest way to do this is by passing off all the actual work to python. This requires that you have a python environment that has pyhdf installed. Honestly, the bulk of the work is going to be actually installing pyhdf, and I'm afraid that I can't help you there. Assuming that you do have a python environment with pyhdf installed, the rest of this ...


5

{{a}, list1, list2, {b, c}} = Import[filename, "Table"] (* {{10}, {1, 2, 3}, {4, 5, 6, 7, 8}, {1000, 100}} *) Notice how the left-hand side mimics the structure of the right-hand side, which you can see in the output line: a nested list of lists representing the numbers on the different lines in the file.


5

I'm assuming the OP wants "\\sqrt{2}" to turn into the equivalent of $\sqrt{2}$ or $\sqrt{2}$, which would Sqrt[2] in Mathematica. The command ToExpression[s, TeXForm] does not seem to handle the square roots, when they are embedded in a matrix, as in the OP's string. The matrix format of TeX is so straightforward that one can split it up into a list of ...


5

ToExpression is very fast for correct Mathematica syntax input. So the key idea is to create an input string for ToExpression that delivers the expected result for the huge string database in one go: StringData // Extract[{All, 2}] // StringRiffle[#, {"{{", "Nothing},{", "Nothing}}"}] & // ToExpression The odd looking "Nothing}" in ...


4

In my comment, I pointed to how exiftool and ffprobe can be used to read the frame count. Apparently, VirtualDub can too. But, it turns out, these tools aren't doing anything we can't also do easily in Mathematica. The AVI metadata header is documented e.g. here. What this says is that we can retrieve the metadata by reading the bytes at the beginning of the ...


4

You can use jsoupLink for this: Needs["jsoupLink`"] html = Import[ "https://trailhead.salesforce.com/content/learn/modules/european-union-privacy-law-basics/get-to-know-eu-privacy-law?trail_id=learn-privacy-and-data-protection-law", "HTMLDOM" ]; texts = #["AllText"] & /@ html["Select", ".unit-content p"];


4

ToExpression[StringReplace[ToString[file], ";" -> ","]] {{0.0472, 120.9091}, {0.0454, 113.0303}, {0.0441, 106.6667}, {0.0442, 106.6667}, {0.0437, 103.3333}, {0.0425, 95.1515}, {0.0409, 83.6364}, {0.0387, 72.7273}, {0.0354, 59.697}, {0.0317, 45.7576}, {0.0275, 34.8485}, {0.0234, 24.8485}, {0.0155, 12.1212}, {0.0115, 6.6667}, {0.0072, ...


4

ToExpression[file /. {a_String} :> StringSplit[a, ";"]]


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