# Tag Info

59

I have worked in pattern classification and machine learning for decades, taught the subject in a number of elite academic departments, am writing the third edition of Pattern classification by Duda, Hart and Stork as well as its companion computer manual in Mathematica, and am an expert Mathematica programmer, a solid Matlab programmer, but very weak in R ...

58

In this answer, I will concentrate on the colors only to create something like this Copying the colors from python is a very fast way to get similar results. Nevertheless, the best way to understand what's happening is still to read the underlying publication that was used in seaborn: A colour scheme for the display of astronomical intensity images There, ...

58

General comments First, if you plan to use multi-dimensional integrals it is better to test with multi-dimensional integrals not with one dimensional ones. One might think that the test in the question is an appropriate one if multi-dimensional integration is done by the integrator in a recursive manner. This seems to be case for scipy.integrate.nquad (see ...

51

Streaming module - general, and the case at hand Starting with V10.1, there is an undocumented support for certain lazy operations in Mathematica. However, the primary goal of Streaming is to support out of core computations reasonably efficiently, and lazy operations are only the secondary goal. Example: lazy infinite lists and an analog of enumerate ...

48

Mathematica doesn't have the depth of algorithm support that is present in R or Python. Julia has much more limited algorithm support but does exhibit a good turn of speed. The few algorithms that Mathematica does support are not particularly well exposed for the type of tweaking needed to win Kaggle competitions. Mathematica, as of version 10, supports ...

41

Broadcasting vs Listability NumPy broadcasting lets you perform, in efficient way, element-wise operations on arrays, as long as dimensions of those arrays are considered "compatible" in some sense. Mathematica also has such mechanism. Some Mathematica functions are Listable and also allow you to perform element-wise operations on nested lists with ...

40

Styling closer to your example, using The Toad's colors: colors = {RGBColor[{0.9312692223325372, 0.8201921796082118, 0.7971480974663592}], RGBColor[{0.8822898168737189, 0.695820866705742, 0.7065457119485431}], RGBColor[{0.8135380254700676, 0.5705055182357822, 0.639280859468155}], RGBColor[{0.7195800708349119, 0.45537982893127477, 0....

39

Using color functions efficiently in data visualizations is more of an art than a recipe, so don't worry if you're not "good" at it yet. It's only a matter of time :) Copying the color schemes from seaborn: The best way to mimic those color schemes in Mathematica would be to copy the RGB values from seaborn for your preferred color scheme. You can find ...

38

You're asking for the biggest distinguishing feature of Mathematica - other than computer algebra. To give a really general answer, I would list as my number one choice the availability of curated knowledge, including free-form input. Other languages also have some limited ability to do this, but I think Mathematica has a head start and is moreover ...

37

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} *)

32

Mathematica 12.0 brings two new features that make this easier to do than it was before: ExternalFunction Wolfram Client for Python Below we implement a function nxFunction that automatically handles translating Mathematica expressions of interest to Python, as well as converting the results back. The usage will be nxFunction["someNetworkxFunction"][...

28

General remarks Before giving several (biased) answers to the question As a developer I'd like to ask if there any other significant advantages to Mathematica - are there any areas where Mathematica is still vastly superior to the Python stack other than in computer algebra? I would like to mention my Python background. 17 years ago I programmed in ...

27

Challenging NumPy's performance will be extremely difficult, and thus the effort of implementing this is not likely to be worthwhile. The reason is that the multiple-transpose method, even though it has some overhead, is already a very good way to accomplish this type of operation in Mathematica: mat = RandomReal[1., {40000000, 2}]; vec = {1., 2.}; ...

23

Since python has pretty close syntax as Fortran, converting the expression to FortranForm is what I usually do in this case. testing2 = ExpandAll[ D[(x - A)^2 + (y - B)^2 + (v - C)^2 + (x + y - (S + v) - D)^2 - λ1*x - λ2*y - λ3* v - λ4*(x + y - (S + v)), {{x, y, v}}]] sols = {x, y, v, x, y, v, λ1, λ2, λ3, λ4} /. Solve[Thread[ ...

22

FortranForm gets you close. ( Fortran and Python use the same syntax for most things ) pw = PageWidth /. Options[$Output]; SetOptions[$Output, PageWidth ->Infinity]; FortranForm[ expression /. E^x_ :> exp[x] ] SetOptions[$Output, PageWidth -> pw]; (1.*(43.013537902165325 + 43.013537902165346*exp(0.003288590604026849*t))**2)/(... 22 Mathematica doesn't do that because it's ambiguous. Note that Mathematica is perfectly happy to do "broadcasting", as you call it, if the second array is transposed: In[1]:= {1, 2} + {{1, 2, 3}, {2, 3, 4}} Out[1]= {{2, 3, 4}, {4, 5, 6}} This, in fact, gives you one way to get the result that you want: In[2]:= Transpose[{1, 2} + Transpose@{{1, 2, 3}, {2, 3,... 20 Building off of @M.R.'s idea, it is possible to set up an interactive python shell using StartProcess as opposed to RunProcess, allowing for much more flexible connectivity between Python and Wolfram without as much overhead. In it's simplest form, one can open a connection, interact with it, and close it using the following example: path = "e:\\Programs\\... 17 Here is a more robust solution using Process: Clear[runPython]; runPython::badCommand ="Python code failed to run with message StandardError`";$pyimports="from random import randint "; runPython[str_String, imports_:$pyimports] := Module[ {pyscrpt = ToString[$pyimports<>str, CharacterEncoding->"ASCII"], file=CreateTemporary[], res}, ...

17

The function you want is MapThread - no Transpose needed. MapThread[f[#1, #2, #3] &, {L, A, Inc}] (* {f[874, 120 \[Degree], 0.246091], f[4513, 140 \[Degree], 1.15541], f[1487, 180 \[Degree], 1.15541]} *) And for your function: MapThread[N[{#1*Cos[#2], #1*Sin[#2]*Cos[#3], #1*Sin[#2]*Sin[#3]}] &, {L, A, Inc}] (* {{-437., 734.102, 184.394}, {-...

17

As suggested by @Jens, HDF5 can be fast imported and manipulated in Mathematica. The performance of importing HDF5 is as efficient as MAT file in Python and you can read only a part of HDF5 file into memory. From the question, Mathematica is about 3~4 times slower in reading MAT files. The speed of reading HDF5 files are very close to the speed in Python. ...

17

From my perspective, (I was the original developer for Evolved Analytics' DataModeler Mathematica add-on package, www.evolved-analytics.com), what Mathematica brings to the table is the semi-seamless integration of symbolics and numerics as well as the freeform programming. From the point of view of symbolic regression, things are possible which are very ...

17

This is second part of answer 99553 that exceeded maximum allowed size. 3. LibraryLink JIT In this approach we'll create functions generating optimized SymbolicC expression for given function and given "broadcasting types" of argument tensors. Here specific "broadcasting type" of tensor means: data type (Integer, Real, or Complex), rank of tensor, and ...

17

I believe you're not in the correct direction, optimizing your Mathematica code should be more practical and easier. (You've already learned the numeric capability of Mathematica under your previous question, don't you? ) Anyway, here's my attempt to minimize your toy function f using Python in Mathematica. I know little about Python, feel free to point out ...

16

I actually failed miserably in a Kaggle contest using Mathematica Enterprise. I tested every single variation of Classify and Predict and even combinations of the two. I also tested Microsoft ML Studio, Google Prediction API, IBM Watson, BigML and others. Amazon ML got me the highest score but they all failed miserably in comparison to the custom ...

15

Since 11.2 Mathematica has supported ExternalEvaluate and since 11.3 this functionality has been conveniently available simply by beginning an input cell with > which produces an external code cell: The output of these cells is a Wolfram Language expression that you can then compute with.

15

The os.system command will not help you, because it does not return/provide the output of the command executed. What you want is to have a look at this answer on Stack Overflow to see how you can get the stdout of a command into a Python variable. In your Mathematica script you simply Print the result and with the given method in the other answer you ...

15

I was able to do it. I'll post what I did in case somebody else needs it. So far it works really nice. Just follow the instructions from the repository, and modify the Makefile.linux with the following code, saved as Makefile.linux: # Set the paths according to your MathLink Developer Kit location. # (The paths should not contain whitespaces) ...

15

To get this out of the way: I believe the Import::nopythonevals message will be issued by Import[..., "PythonExpression"] if there are no usable external evaluators set up. First make sure that you have set up Python correctly (including installing pyzmq), and registered an external evaluator. As you can see in my question, I have already done this, yet ...

15

I do not think there is general way to convert large chunk of code from Python to Mathematica (such as complete functions). But for individual expressions you could try this do it via Latex. In Python In[24]: from sympy import * In[25]: x,y=symbols('x y') In[26]: expr= 1+2**(x+y)*integrate(sin(x),x)-2*tan(x) In[27]: expr Out[27]: -2**(x + y)*cos(x) - 2*tan(...

14

This one is very close to your Python code Join @@ Table[Append[a, i], {a, A}, {i, Intersection[Range[3], a]}] {{1, 2, 3, 1}, {1, 2, 3, 2}, {1, 2, 3, 3}, {2, 3, 4, 2}, {2, 3, 4, 3}, {3, 4, 5, 3}}

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