Hot answers tagged

92

TL;DR: A package (Mathematica v10) can be found at the very bottom of this post. UPDATES 6: Tiny update: Import can now use the ".bvh" extension to determine the import type. The code that does this is ugly, but I don't see any other way at the moment. out = Import["C:\\Female1_C03_Run.bvh"] 5: Added error checking and registered the package as an ...


39

The following is something I made while trying to solve another (similar) problem (*FindCurvedPath Replacement*) ClearAll[findCurvedPath2, findClosedPath2]; findClosedPath2[inptList_, cutoff_] := Append[#, #[[1]]] &@ findCurvedPath2[inptList, cutoff] findCurvedPath2[inptList_, cutoff_] := Block[{ ...


37

I think you can use Names["Global`*"] to get the name: a = RandomReal[{0, 1}, 10]; SetDirectory[$TemporaryDirectory]; DumpSave["1.mx", a]; Quit[] SetDirectory[$TemporaryDirectory]; << 1.mx Names["Global`*"] (*{"a"}*)


34

64-bit Windows only Note for Mathematica 11.3: There is a potential conflict between MathMF and the built-in MediaTools package. See here for details and here for an example of how to use MediaTools in place of MathMF.   Note for Mathematica version 10: The Wolfram Library has been updated in version 10 and you will need to recompile the MathMF DLL. ...


34

You can use the binary format to speed up the process: python side import numpy as np array = np.random.rand(100000000); array.astype('float32').tofile('np.dat') Mathematica side data = BinaryReadList["np.dat", "Real32"]; // AbsoluteTiming (* {2.56679, Null} *) data // Dimensions (* {100000000} *)


33

Get all the files here. .NET Mathematica Word Library You will need to use a Microsoft library to open word documents. In a language such as .Net it is very easy; just open Visual Studio, reference the Microsoft.Office.Interop.Word .NET DLL (for Words) and the C:\Program Files\Open XML SDK\V2.5\lib\DocumentFormat.OpenXml.dll (for Formulas in the MathML ...


32

This seems to work: Import["data.csv", "table", FieldSeparators -> ";"] Should be Import["data.csv", "Table", "FieldSeparators" -> ";"] See help for "Table" element (ref/format/Table), specifically Options section.


32

Mathematica is interpreting c as a currency marker. This is controlled by the "CurrencyTokens" import option for "Table". The default setting for "CurrencyTokens" is {{"$ ", "£", "¥", "€"}, {"c ", "¢", "p ", "F "}} so this also happens with the letters p or F. The workaround is ImportString["123c", "Table", "CurrencyTokens" -> None] (* {{"123c"}} *) ...


31

Your problem is that you've got a slight misunderstanding of the different types of items that ReadList can read. That's OK, it can be a little confusing. To begin with: String, Number, Expression, etc. are not sub-types of Record. They are all separate types with their own rules for how they are read. The RecordSeparators option is only applied to ...


30

Using the (deprecated but easy) API documented here, result = Import[ "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey", "JSON"] Import["url" /. ("results" /. ("responseData" /. result))[[1]]] If you hit the service too many times, it'll lock you out for a while. Here's another example that gives the 24th-32nd results:...


28

Well, I suspect this question will get closed because it is a bit broad, but I've played around with image tracking and thought I'd show what I've done in case it's helpful. I was interested in learning some physics, and have the following video: To do the tracking, I smoothed out the images and converted them to black and white, which allows for the ...


27

If you use Import/Export to load/save .mx files, instead of DumpSave, then the variable does not get embedded in the file, and you can assign it to any variable of choice in the new session. x = RandomReal[1, {100, 100}]; Export["~/tmp.mx", x]; y = Import["~/tmp.mx"]; x == y (* True *)


26

Certainly. There have indeed been some changes to certain tags in the 2.1 API and also to the method to sort out how many pages to import. And, since we are now a full site under StackExchange, the server has changed and a site parameter was necessary. I did a bit of clean-up, hardened the code a little to accommodate connection failures, made the basic ...


25

Taking user5601's suggestion to do a little demo, I quickly whipped this up as an example of ProcessLink being used to do non-trivial communication between Mathematica and an external program, but with much less ceremony than using ProcessLink or MathLink. Let's take this little Go program: package main import "net/http" import "bufio" import "os" import "...


24

With this function a random integer is inserted in the e-mail address (gmailuser@gmail.com becomes gmailuser+randominteger@gmail.com) and then the hash value is computed. The hash value is used to get the corresponding identicon from the Gravatar website. This approach can address also some privacy concerns. generatePic[email_] := Module[{emailparts, ...


24

I assume you have Maple to use. If so, Simply open Maple and type the Mathematica command itself directly into Maple using the FromMma package built-into Maple, like this: restart; with(MmaTranslator); #load the package (*[FromMma, FromMmaNotebook, Mma, MmaToMaple]*) and now can use it FromMma(`Integrate[Cos[x],x]`); One can also use Maple convert ...


24

Here's a much faster, purely Mathematica way than using Import to import your data: UPDATE As Leonid mentioned the previous code doesn't exactly replicate Import. The truth is I was only trying to retrieve the numerical part. Here's an updated version that tries to replicate the output from Import. readYourCSV2[file_String?FileExistsQ, n_Integer] := ...


23

Mathematica can Import your file, and the result is a handy set of graphical primitives. So in this particular case we can do all the steps needed for data extraction without leaving Mathematica. I will not do the whole work for you but show the correct approach to the problem. First, you Import the file and check in what form the curves of interest are ...


23

Analysis Reading the data is not the issue. I can read the data as strings quite fast. str = OpenRead["train-7000.csv"]; (data = ReadList[str, String]); // AbsoluteTiming//First (* 0.453251 *) Memory use is modest too: data // ByteCount (* 48550344 *) It's only slightly larger than the file on disk: FileByteCount["train-7000.csv"] (* 46483707 *) The ...


22

Reading the file as Import["file.jpeg", "ImageNoExif"] is noticeably faster on my machine than the default Import["file.jpeg", "Image"] Benchmark in 11.1: Import["~/Desktop/Untitled.jpg", "Image"]; // RepeatedTiming (* {0.054, Null} *) Import["~/Desktop/Untitled.jpg", "ImageNoExif"]; // RepeatedTiming (* {0.025, Null} *) This is not a full solution, ...


21

The file appears to be a Unified Summary File from the Schlumberger Eclipse Reservoir Simulator. This file format uses Compaq Visual Fortran variable length record encoding. Mathematica does not offer any built-in functionality to read this file format, so we will have to parse it ourselves. We start by defining a convenience function to read big-endian ...


21

As J.M. notes in a comment, AnglePath allows paths to be specified in relative terms instead of absolute terms: Graphics[ Line@AnglePath[{{60, 0°}, {60, 120°}, {60, 120°}}] ] Note that the figure had to be closed explicitly with an extra line. We can remedy that by using JoinedCurve. Graphics[ JoinedCurve[Line@AnglePath[{{60, 0°}, {60, 120°}}], ...


20

webShot[URI_String] := Import["http://www.sciweavers.org/iWeb2Shot?url=" <> URI] webShot["google.com"] Another one: webShot["http://mathematica.stackexchange.com/questions/20486/import-the-thumbnail-of-an-internet"]


20

This is an unfortunate oversight on the part of Wolfram and would be of general interest, so I wrote a LibraryFunction in C (compiled using CreateLibrary) that will decompress data compressed using the Unix compress command (i.e. .Z files, compressed in the LZW format). Included are functions to extend Import and ImportString for the LZW format. You can ...


20

I'm Riccardo, current developer of URLRead in WL and I have some experience working with encoding in WL. I would like to inform you that this is not a bug. In modern versions of mathematica we have ByteArray, and this is a representation of bytes. But for decades strings have been both bytes and "unicode" at the same time. The problem here is that all ...


19

Use URLFetch in Mathematica 9.0.1.


19

Leonid has shown how to get a big improvement in speed with Java and has mentioned that by using a library function written e.g. in C you could probably get further improvement as you can then avoid additional copies/data transfer. I just wanted to add an all Mathematica solution as it probably indicates how similar problems can be tackled where for ...


19

I'd use .mx files (Export / Import in "MX" format): Export["myFile.mx",list] and Import["myFile.mx"] This is fast, and does not really involve serialization / parsing in the usual sense (via strings). In other words, mx files bypass the high-level parsing, populating internal structures at lower level. In addition, mx files preserve packed arrays.


19

We can start by importing the file as an XMLObject: $url = "https://dl.dropboxusercontent.com/u/1012958/iTunes%20Library.xml"; $xml = Import[$url, {"XML", "XMLObject"}]; Short[$xml, 4] (* XMLObject[Document][ { XMLObject[Declaration][Version->1.0,Encoding->UTF-8] , XMLObject[Doctype][plist,Public->-//Apple Computer//DTD PLIST 1.0//EN,&...


19

This is a complementary answer, which shows mostly how to reduce memory use rather than speed (although later I might update it to address the speed issue as well). This answer is based on an undocumented functionality, so the usual warning applies: there is no guarantee that the method suggested below will work in future versions. Using undocumented ...


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