Analogies to Help New Users

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
27
down vote

favorite
10












In many of the classes that I teach, I require students to learn the basics of Mathematica which we use throughout the semester to do computations and to submit homeworks (in notebook form). Some students really like this and some... not so much.



Since I teach in an engineering department, almost everyone already knows some programming language: Matlab, python, java, or C are the most common, though there is quite a variety. One thing that I have found pretty effective is to try and relate Mathematica formalisms, structures, and ideas to those that students already know. For example:



$-$ When talking about using the Listable Attribute of functions, I compare this to Matlab's vectorization



$-$ When talking about alternatives for loops, Mathematica's Table function is analogous to python's List Comprehensions, for example, observe the similarity between



squares = [x**2 for x in range(10)]


and



squares = Table[x^2, x, Range[10]]


$-$ Mathematica's Notebook format is analogous to Jupyter notebooks which merge word processing, computation, and interactive presentations.



My question is this: What are some other analogies between Mathematica functions, expressions, and structures that might be helpful to new users in understanding "what Mathematica is thinking" or "why it works that way"?



Update: It seems that we have some very good answers for Matlab and for python. How about other languages? Any nice analogies for/with other popular languages?










share|improve this question























  • Do you have materials from your courses that you could make available? Much obliged.
    – Rabbit
    Sep 8 at 15:20






  • 9




    It is the other way around: Jupyter notebooks are (still poor) analogs of Mathematica notebooks.
    – Anton Antonov
    Sep 8 at 15:47






  • 1




    @bills I was half-joking, referring to the historical time-line of notion and implementation of "computational notebook". You are referring to the exposure time-lines of individuals/students.
    – Anton Antonov
    Sep 8 at 16:00






  • 4




    @sunt05 some percentage of the students in my class feel the same way. But the class is not about learning Mathematica or learning python, but about image processing. One thing python lacks is the easy interactivity of Mathematica, which is really key when examining many different variations on parameters, filters, and processing methods. I'd be happy to see an answer from you with more python-esque analogies
    – bill s
    Sep 10 at 21:17







  • 7




    Perhaps analogies are more harmful than helpful beyond a certain point. They might encourage students to think in Python and try to translate their Python solution directly to Mathematica. That often results in a hideously complex and inefficient solution. An alternative approach would be to show how certain basic tasks are accomplished. Describe those basic tasks in English, not in Python. The tasks should be chosen based on what is taught in your course, and what mistakes student most commonly made in past years.
    – Szabolcs
    Sep 11 at 13:51














up vote
27
down vote

favorite
10












In many of the classes that I teach, I require students to learn the basics of Mathematica which we use throughout the semester to do computations and to submit homeworks (in notebook form). Some students really like this and some... not so much.



Since I teach in an engineering department, almost everyone already knows some programming language: Matlab, python, java, or C are the most common, though there is quite a variety. One thing that I have found pretty effective is to try and relate Mathematica formalisms, structures, and ideas to those that students already know. For example:



$-$ When talking about using the Listable Attribute of functions, I compare this to Matlab's vectorization



$-$ When talking about alternatives for loops, Mathematica's Table function is analogous to python's List Comprehensions, for example, observe the similarity between



squares = [x**2 for x in range(10)]


and



squares = Table[x^2, x, Range[10]]


$-$ Mathematica's Notebook format is analogous to Jupyter notebooks which merge word processing, computation, and interactive presentations.



My question is this: What are some other analogies between Mathematica functions, expressions, and structures that might be helpful to new users in understanding "what Mathematica is thinking" or "why it works that way"?



Update: It seems that we have some very good answers for Matlab and for python. How about other languages? Any nice analogies for/with other popular languages?










share|improve this question























  • Do you have materials from your courses that you could make available? Much obliged.
    – Rabbit
    Sep 8 at 15:20






  • 9




    It is the other way around: Jupyter notebooks are (still poor) analogs of Mathematica notebooks.
    – Anton Antonov
    Sep 8 at 15:47






  • 1




    @bills I was half-joking, referring to the historical time-line of notion and implementation of "computational notebook". You are referring to the exposure time-lines of individuals/students.
    – Anton Antonov
    Sep 8 at 16:00






  • 4




    @sunt05 some percentage of the students in my class feel the same way. But the class is not about learning Mathematica or learning python, but about image processing. One thing python lacks is the easy interactivity of Mathematica, which is really key when examining many different variations on parameters, filters, and processing methods. I'd be happy to see an answer from you with more python-esque analogies
    – bill s
    Sep 10 at 21:17







  • 7




    Perhaps analogies are more harmful than helpful beyond a certain point. They might encourage students to think in Python and try to translate their Python solution directly to Mathematica. That often results in a hideously complex and inefficient solution. An alternative approach would be to show how certain basic tasks are accomplished. Describe those basic tasks in English, not in Python. The tasks should be chosen based on what is taught in your course, and what mistakes student most commonly made in past years.
    – Szabolcs
    Sep 11 at 13:51












up vote
27
down vote

favorite
10









up vote
27
down vote

favorite
10






10





In many of the classes that I teach, I require students to learn the basics of Mathematica which we use throughout the semester to do computations and to submit homeworks (in notebook form). Some students really like this and some... not so much.



Since I teach in an engineering department, almost everyone already knows some programming language: Matlab, python, java, or C are the most common, though there is quite a variety. One thing that I have found pretty effective is to try and relate Mathematica formalisms, structures, and ideas to those that students already know. For example:



$-$ When talking about using the Listable Attribute of functions, I compare this to Matlab's vectorization



$-$ When talking about alternatives for loops, Mathematica's Table function is analogous to python's List Comprehensions, for example, observe the similarity between



squares = [x**2 for x in range(10)]


and



squares = Table[x^2, x, Range[10]]


$-$ Mathematica's Notebook format is analogous to Jupyter notebooks which merge word processing, computation, and interactive presentations.



My question is this: What are some other analogies between Mathematica functions, expressions, and structures that might be helpful to new users in understanding "what Mathematica is thinking" or "why it works that way"?



Update: It seems that we have some very good answers for Matlab and for python. How about other languages? Any nice analogies for/with other popular languages?










share|improve this question















In many of the classes that I teach, I require students to learn the basics of Mathematica which we use throughout the semester to do computations and to submit homeworks (in notebook form). Some students really like this and some... not so much.



Since I teach in an engineering department, almost everyone already knows some programming language: Matlab, python, java, or C are the most common, though there is quite a variety. One thing that I have found pretty effective is to try and relate Mathematica formalisms, structures, and ideas to those that students already know. For example:



$-$ When talking about using the Listable Attribute of functions, I compare this to Matlab's vectorization



$-$ When talking about alternatives for loops, Mathematica's Table function is analogous to python's List Comprehensions, for example, observe the similarity between



squares = [x**2 for x in range(10)]


and



squares = Table[x^2, x, Range[10]]


$-$ Mathematica's Notebook format is analogous to Jupyter notebooks which merge word processing, computation, and interactive presentations.



My question is this: What are some other analogies between Mathematica functions, expressions, and structures that might be helpful to new users in understanding "what Mathematica is thinking" or "why it works that way"?



Update: It seems that we have some very good answers for Matlab and for python. How about other languages? Any nice analogies for/with other popular languages?







programming functional-style education






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked Sep 8 at 14:34









bill s

51.3k375146




51.3k375146











  • Do you have materials from your courses that you could make available? Much obliged.
    – Rabbit
    Sep 8 at 15:20






  • 9




    It is the other way around: Jupyter notebooks are (still poor) analogs of Mathematica notebooks.
    – Anton Antonov
    Sep 8 at 15:47






  • 1




    @bills I was half-joking, referring to the historical time-line of notion and implementation of "computational notebook". You are referring to the exposure time-lines of individuals/students.
    – Anton Antonov
    Sep 8 at 16:00






  • 4




    @sunt05 some percentage of the students in my class feel the same way. But the class is not about learning Mathematica or learning python, but about image processing. One thing python lacks is the easy interactivity of Mathematica, which is really key when examining many different variations on parameters, filters, and processing methods. I'd be happy to see an answer from you with more python-esque analogies
    – bill s
    Sep 10 at 21:17







  • 7




    Perhaps analogies are more harmful than helpful beyond a certain point. They might encourage students to think in Python and try to translate their Python solution directly to Mathematica. That often results in a hideously complex and inefficient solution. An alternative approach would be to show how certain basic tasks are accomplished. Describe those basic tasks in English, not in Python. The tasks should be chosen based on what is taught in your course, and what mistakes student most commonly made in past years.
    – Szabolcs
    Sep 11 at 13:51
















  • Do you have materials from your courses that you could make available? Much obliged.
    – Rabbit
    Sep 8 at 15:20






  • 9




    It is the other way around: Jupyter notebooks are (still poor) analogs of Mathematica notebooks.
    – Anton Antonov
    Sep 8 at 15:47






  • 1




    @bills I was half-joking, referring to the historical time-line of notion and implementation of "computational notebook". You are referring to the exposure time-lines of individuals/students.
    – Anton Antonov
    Sep 8 at 16:00






  • 4




    @sunt05 some percentage of the students in my class feel the same way. But the class is not about learning Mathematica or learning python, but about image processing. One thing python lacks is the easy interactivity of Mathematica, which is really key when examining many different variations on parameters, filters, and processing methods. I'd be happy to see an answer from you with more python-esque analogies
    – bill s
    Sep 10 at 21:17







  • 7




    Perhaps analogies are more harmful than helpful beyond a certain point. They might encourage students to think in Python and try to translate their Python solution directly to Mathematica. That often results in a hideously complex and inefficient solution. An alternative approach would be to show how certain basic tasks are accomplished. Describe those basic tasks in English, not in Python. The tasks should be chosen based on what is taught in your course, and what mistakes student most commonly made in past years.
    – Szabolcs
    Sep 11 at 13:51















Do you have materials from your courses that you could make available? Much obliged.
– Rabbit
Sep 8 at 15:20




Do you have materials from your courses that you could make available? Much obliged.
– Rabbit
Sep 8 at 15:20




9




9




It is the other way around: Jupyter notebooks are (still poor) analogs of Mathematica notebooks.
– Anton Antonov
Sep 8 at 15:47




It is the other way around: Jupyter notebooks are (still poor) analogs of Mathematica notebooks.
– Anton Antonov
Sep 8 at 15:47




1




1




@bills I was half-joking, referring to the historical time-line of notion and implementation of "computational notebook". You are referring to the exposure time-lines of individuals/students.
– Anton Antonov
Sep 8 at 16:00




@bills I was half-joking, referring to the historical time-line of notion and implementation of "computational notebook". You are referring to the exposure time-lines of individuals/students.
– Anton Antonov
Sep 8 at 16:00




4




4




@sunt05 some percentage of the students in my class feel the same way. But the class is not about learning Mathematica or learning python, but about image processing. One thing python lacks is the easy interactivity of Mathematica, which is really key when examining many different variations on parameters, filters, and processing methods. I'd be happy to see an answer from you with more python-esque analogies
– bill s
Sep 10 at 21:17





@sunt05 some percentage of the students in my class feel the same way. But the class is not about learning Mathematica or learning python, but about image processing. One thing python lacks is the easy interactivity of Mathematica, which is really key when examining many different variations on parameters, filters, and processing methods. I'd be happy to see an answer from you with more python-esque analogies
– bill s
Sep 10 at 21:17





7




7




Perhaps analogies are more harmful than helpful beyond a certain point. They might encourage students to think in Python and try to translate their Python solution directly to Mathematica. That often results in a hideously complex and inefficient solution. An alternative approach would be to show how certain basic tasks are accomplished. Describe those basic tasks in English, not in Python. The tasks should be chosen based on what is taught in your course, and what mistakes student most commonly made in past years.
– Szabolcs
Sep 11 at 13:51




Perhaps analogies are more harmful than helpful beyond a certain point. They might encourage students to think in Python and try to translate their Python solution directly to Mathematica. That often results in a hideously complex and inefficient solution. An alternative approach would be to show how certain basic tasks are accomplished. Describe those basic tasks in English, not in Python. The tasks should be chosen based on what is taught in your course, and what mistakes student most commonly made in past years.
– Szabolcs
Sep 11 at 13:51










3 Answers
3






active

oldest

votes

















up vote
24
down vote













Imho some important things to translate between Matlab and Mathematica:



  • "everything is a matrix (or inefficient)" vs. "everything is an expression"


  • indexing into arrays: : vs. All


  • indexing into arrays: j:i:k vs. j;;k;;i


  • constructing ranges: j:i:k vs. Range[j,k,i]


  • column-major vs. row-major!: mat(:) vs. Flatten[Transpose[mat]] or (mat')(:) vs. Flatten


  • combining tensors: cat vs. Join and ArrayFlatten


  • anonymous functions: @(x) x^2 vs. #^2& or x [Function] x^2


  • building simple tensors: zeroes, ones vs. ConstantArray


  • more tensors: eye and speye vs. IdentityMatrix and
    IdentityMatrix[#,SparseArray]&


  • diag and spdiags vs. DiagonalMatrix and DiagonalMatrix[SparseArray[#]] & / SparseArray together with Band (but also diag vs. Diagonal btw.)


  • even more tensors: rand vs. RandomReal


  • loops: for vs. Do, Table, Array, and Map (and not For!!11eleven)


  • arrayfun and cellfun vs. Map (with level spec -1) (special thanks to mikado for pointing this one out)


  • while and repeat vs. While, but also NestWhile, NestWhileList, FixedPoint, and FixedPointList


  • if ... else ... end vs. If


  • if ... elseif... elseif... end vs. Which


  • piecewise vs., well, Piecewise


  • solving linear systems: and / vs. LinearSolve and LinearSolve[#1][#2, "T"] &


  • more linear systems: pinv vs. LeastSquares and PseudoInverse


  • struct vs. Association


  • cell vs. List


Certainly less important



  • kron vs. KroneckerProduct


  • meshgrid vs. Tuples (Due to the intuitive plotting in Mathematica, Tuples within Mathematica has not nearly the same importance as meshgrid has within Matlab.)


  • class vs. tags (TagSet and TagSetDelayed) (though each Matlab programmer I've ever met refused to use classes...)


  • isa vs. Head and patterns


  • mex vs. Compile (and LibraryLink for the pro users)






share|improve this answer






















  • One could also mention Piecewise in the context of If and Which...
    – kirma
    Sep 14 at 10:36






  • 1




    @kirma Good point. I added it, but compared it to piecewise rather than to if. ;)
    – Henrik Schumacher
    Sep 14 at 12:03











  • Is IdentityMatrix[@,SparseArray]& intended to be IdentityMatrix[#,SparseArray]&? Might also be worthwhile to point out DiagonalMatrix, though I don't recall if there's a clear Matlab analog.
    – eyorble
    Sep 14 at 12:31










  • @eyorble Good point. Corrected it. There are als diag and spdiags in Matlab.
    – Henrik Schumacher
    Sep 14 at 12:38










  • @HenrikSchumacher Ah. I've never used Matlab. ;)
    – kirma
    Sep 14 at 13:06

















up vote
9
down vote













When a language, e.g., Python, not emphasizing but has to talk about "functional programming", usually it speaks about three functions: map, filter and reduce. I always think comparison a good approach to learn things, so below I share the comparison I made before.



enter image description here



enter image description here



enter image description here



Besides, Function (&) vs lambda, Array, Table vs "list comprehensions" (Table has been mentioned but Range is redundant.).






share|improve this answer






















  • I think if you want to talk correspondence, the entirety of itertools is big. It provides a slew of utilities that Mathematica has, but does so in a more efficient lazy fashion.
    – b3m2a1
    12 hours ago

















up vote
6
down vote













For those with experience in python, WRI has already provided a nice introductory tutorial along with many analogies.



However, for the class intended for image processing as mentioned by the OP, pure python is for certain not enough: numpy, pandas, scipy and pillow are some of the essential packages to go with.






share|improve this answer




















  • As someone who has used pillow a fair amount, I do tend to think it is less-intuitive and certainly less-powerful than Mathematica. It is nice to know that it exists and get some sense for how to use it for when you lose that academic Mathematica license and the cost is prohibitive, but as they say, "use the right tool for the job" and for maybe the first time ever, the right tool is Mathematica. I do enjoy numpy, though, as a stand in for Mathematica arrays. It is often much more efficient.
    – b3m2a1
    12 hours ago











  • @b3m2a1 Actually I was really reluctant to write up this post days ago as I love Mathematica to death. However, I feel helpless now and then if I want to communicate my research outcome with others in Mathematica. As long as WRI stays with their current business model, it is hopeless to see new blood flowing into the Mathematica usership, not to mention discipline-specific python packages are moving really fast : I personally interact with atmospheric models a lot and feel Mathematica lacks essential tools to deal with those tools.
    – sunt05
    11 hours ago











  • I won't deny any of that. Modern research is done is python (and some R and MATLAB) and Mathematica has decidedly abdicated its once considerable position in that. My sole argument was about image processing with Mathematica vs. pillow. In that specific case, Mathematica still outperforms python in usability and performance.
    – b3m2a1
    11 hours ago










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181499%2fanalogies-to-help-new-users%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
24
down vote













Imho some important things to translate between Matlab and Mathematica:



  • "everything is a matrix (or inefficient)" vs. "everything is an expression"


  • indexing into arrays: : vs. All


  • indexing into arrays: j:i:k vs. j;;k;;i


  • constructing ranges: j:i:k vs. Range[j,k,i]


  • column-major vs. row-major!: mat(:) vs. Flatten[Transpose[mat]] or (mat')(:) vs. Flatten


  • combining tensors: cat vs. Join and ArrayFlatten


  • anonymous functions: @(x) x^2 vs. #^2& or x [Function] x^2


  • building simple tensors: zeroes, ones vs. ConstantArray


  • more tensors: eye and speye vs. IdentityMatrix and
    IdentityMatrix[#,SparseArray]&


  • diag and spdiags vs. DiagonalMatrix and DiagonalMatrix[SparseArray[#]] & / SparseArray together with Band (but also diag vs. Diagonal btw.)


  • even more tensors: rand vs. RandomReal


  • loops: for vs. Do, Table, Array, and Map (and not For!!11eleven)


  • arrayfun and cellfun vs. Map (with level spec -1) (special thanks to mikado for pointing this one out)


  • while and repeat vs. While, but also NestWhile, NestWhileList, FixedPoint, and FixedPointList


  • if ... else ... end vs. If


  • if ... elseif... elseif... end vs. Which


  • piecewise vs., well, Piecewise


  • solving linear systems: and / vs. LinearSolve and LinearSolve[#1][#2, "T"] &


  • more linear systems: pinv vs. LeastSquares and PseudoInverse


  • struct vs. Association


  • cell vs. List


Certainly less important



  • kron vs. KroneckerProduct


  • meshgrid vs. Tuples (Due to the intuitive plotting in Mathematica, Tuples within Mathematica has not nearly the same importance as meshgrid has within Matlab.)


  • class vs. tags (TagSet and TagSetDelayed) (though each Matlab programmer I've ever met refused to use classes...)


  • isa vs. Head and patterns


  • mex vs. Compile (and LibraryLink for the pro users)






share|improve this answer






















  • One could also mention Piecewise in the context of If and Which...
    – kirma
    Sep 14 at 10:36






  • 1




    @kirma Good point. I added it, but compared it to piecewise rather than to if. ;)
    – Henrik Schumacher
    Sep 14 at 12:03











  • Is IdentityMatrix[@,SparseArray]& intended to be IdentityMatrix[#,SparseArray]&? Might also be worthwhile to point out DiagonalMatrix, though I don't recall if there's a clear Matlab analog.
    – eyorble
    Sep 14 at 12:31










  • @eyorble Good point. Corrected it. There are als diag and spdiags in Matlab.
    – Henrik Schumacher
    Sep 14 at 12:38










  • @HenrikSchumacher Ah. I've never used Matlab. ;)
    – kirma
    Sep 14 at 13:06














up vote
24
down vote













Imho some important things to translate between Matlab and Mathematica:



  • "everything is a matrix (or inefficient)" vs. "everything is an expression"


  • indexing into arrays: : vs. All


  • indexing into arrays: j:i:k vs. j;;k;;i


  • constructing ranges: j:i:k vs. Range[j,k,i]


  • column-major vs. row-major!: mat(:) vs. Flatten[Transpose[mat]] or (mat')(:) vs. Flatten


  • combining tensors: cat vs. Join and ArrayFlatten


  • anonymous functions: @(x) x^2 vs. #^2& or x [Function] x^2


  • building simple tensors: zeroes, ones vs. ConstantArray


  • more tensors: eye and speye vs. IdentityMatrix and
    IdentityMatrix[#,SparseArray]&


  • diag and spdiags vs. DiagonalMatrix and DiagonalMatrix[SparseArray[#]] & / SparseArray together with Band (but also diag vs. Diagonal btw.)


  • even more tensors: rand vs. RandomReal


  • loops: for vs. Do, Table, Array, and Map (and not For!!11eleven)


  • arrayfun and cellfun vs. Map (with level spec -1) (special thanks to mikado for pointing this one out)


  • while and repeat vs. While, but also NestWhile, NestWhileList, FixedPoint, and FixedPointList


  • if ... else ... end vs. If


  • if ... elseif... elseif... end vs. Which


  • piecewise vs., well, Piecewise


  • solving linear systems: and / vs. LinearSolve and LinearSolve[#1][#2, "T"] &


  • more linear systems: pinv vs. LeastSquares and PseudoInverse


  • struct vs. Association


  • cell vs. List


Certainly less important



  • kron vs. KroneckerProduct


  • meshgrid vs. Tuples (Due to the intuitive plotting in Mathematica, Tuples within Mathematica has not nearly the same importance as meshgrid has within Matlab.)


  • class vs. tags (TagSet and TagSetDelayed) (though each Matlab programmer I've ever met refused to use classes...)


  • isa vs. Head and patterns


  • mex vs. Compile (and LibraryLink for the pro users)






share|improve this answer






















  • One could also mention Piecewise in the context of If and Which...
    – kirma
    Sep 14 at 10:36






  • 1




    @kirma Good point. I added it, but compared it to piecewise rather than to if. ;)
    – Henrik Schumacher
    Sep 14 at 12:03











  • Is IdentityMatrix[@,SparseArray]& intended to be IdentityMatrix[#,SparseArray]&? Might also be worthwhile to point out DiagonalMatrix, though I don't recall if there's a clear Matlab analog.
    – eyorble
    Sep 14 at 12:31










  • @eyorble Good point. Corrected it. There are als diag and spdiags in Matlab.
    – Henrik Schumacher
    Sep 14 at 12:38










  • @HenrikSchumacher Ah. I've never used Matlab. ;)
    – kirma
    Sep 14 at 13:06












up vote
24
down vote










up vote
24
down vote









Imho some important things to translate between Matlab and Mathematica:



  • "everything is a matrix (or inefficient)" vs. "everything is an expression"


  • indexing into arrays: : vs. All


  • indexing into arrays: j:i:k vs. j;;k;;i


  • constructing ranges: j:i:k vs. Range[j,k,i]


  • column-major vs. row-major!: mat(:) vs. Flatten[Transpose[mat]] or (mat')(:) vs. Flatten


  • combining tensors: cat vs. Join and ArrayFlatten


  • anonymous functions: @(x) x^2 vs. #^2& or x [Function] x^2


  • building simple tensors: zeroes, ones vs. ConstantArray


  • more tensors: eye and speye vs. IdentityMatrix and
    IdentityMatrix[#,SparseArray]&


  • diag and spdiags vs. DiagonalMatrix and DiagonalMatrix[SparseArray[#]] & / SparseArray together with Band (but also diag vs. Diagonal btw.)


  • even more tensors: rand vs. RandomReal


  • loops: for vs. Do, Table, Array, and Map (and not For!!11eleven)


  • arrayfun and cellfun vs. Map (with level spec -1) (special thanks to mikado for pointing this one out)


  • while and repeat vs. While, but also NestWhile, NestWhileList, FixedPoint, and FixedPointList


  • if ... else ... end vs. If


  • if ... elseif... elseif... end vs. Which


  • piecewise vs., well, Piecewise


  • solving linear systems: and / vs. LinearSolve and LinearSolve[#1][#2, "T"] &


  • more linear systems: pinv vs. LeastSquares and PseudoInverse


  • struct vs. Association


  • cell vs. List


Certainly less important



  • kron vs. KroneckerProduct


  • meshgrid vs. Tuples (Due to the intuitive plotting in Mathematica, Tuples within Mathematica has not nearly the same importance as meshgrid has within Matlab.)


  • class vs. tags (TagSet and TagSetDelayed) (though each Matlab programmer I've ever met refused to use classes...)


  • isa vs. Head and patterns


  • mex vs. Compile (and LibraryLink for the pro users)






share|improve this answer














Imho some important things to translate between Matlab and Mathematica:



  • "everything is a matrix (or inefficient)" vs. "everything is an expression"


  • indexing into arrays: : vs. All


  • indexing into arrays: j:i:k vs. j;;k;;i


  • constructing ranges: j:i:k vs. Range[j,k,i]


  • column-major vs. row-major!: mat(:) vs. Flatten[Transpose[mat]] or (mat')(:) vs. Flatten


  • combining tensors: cat vs. Join and ArrayFlatten


  • anonymous functions: @(x) x^2 vs. #^2& or x [Function] x^2


  • building simple tensors: zeroes, ones vs. ConstantArray


  • more tensors: eye and speye vs. IdentityMatrix and
    IdentityMatrix[#,SparseArray]&


  • diag and spdiags vs. DiagonalMatrix and DiagonalMatrix[SparseArray[#]] & / SparseArray together with Band (but also diag vs. Diagonal btw.)


  • even more tensors: rand vs. RandomReal


  • loops: for vs. Do, Table, Array, and Map (and not For!!11eleven)


  • arrayfun and cellfun vs. Map (with level spec -1) (special thanks to mikado for pointing this one out)


  • while and repeat vs. While, but also NestWhile, NestWhileList, FixedPoint, and FixedPointList


  • if ... else ... end vs. If


  • if ... elseif... elseif... end vs. Which


  • piecewise vs., well, Piecewise


  • solving linear systems: and / vs. LinearSolve and LinearSolve[#1][#2, "T"] &


  • more linear systems: pinv vs. LeastSquares and PseudoInverse


  • struct vs. Association


  • cell vs. List


Certainly less important



  • kron vs. KroneckerProduct


  • meshgrid vs. Tuples (Due to the intuitive plotting in Mathematica, Tuples within Mathematica has not nearly the same importance as meshgrid has within Matlab.)


  • class vs. tags (TagSet and TagSetDelayed) (though each Matlab programmer I've ever met refused to use classes...)


  • isa vs. Head and patterns


  • mex vs. Compile (and LibraryLink for the pro users)







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered Sep 8 at 15:01









Henrik Schumacher

40k255120




40k255120











  • One could also mention Piecewise in the context of If and Which...
    – kirma
    Sep 14 at 10:36






  • 1




    @kirma Good point. I added it, but compared it to piecewise rather than to if. ;)
    – Henrik Schumacher
    Sep 14 at 12:03











  • Is IdentityMatrix[@,SparseArray]& intended to be IdentityMatrix[#,SparseArray]&? Might also be worthwhile to point out DiagonalMatrix, though I don't recall if there's a clear Matlab analog.
    – eyorble
    Sep 14 at 12:31










  • @eyorble Good point. Corrected it. There are als diag and spdiags in Matlab.
    – Henrik Schumacher
    Sep 14 at 12:38










  • @HenrikSchumacher Ah. I've never used Matlab. ;)
    – kirma
    Sep 14 at 13:06
















  • One could also mention Piecewise in the context of If and Which...
    – kirma
    Sep 14 at 10:36






  • 1




    @kirma Good point. I added it, but compared it to piecewise rather than to if. ;)
    – Henrik Schumacher
    Sep 14 at 12:03











  • Is IdentityMatrix[@,SparseArray]& intended to be IdentityMatrix[#,SparseArray]&? Might also be worthwhile to point out DiagonalMatrix, though I don't recall if there's a clear Matlab analog.
    – eyorble
    Sep 14 at 12:31










  • @eyorble Good point. Corrected it. There are als diag and spdiags in Matlab.
    – Henrik Schumacher
    Sep 14 at 12:38










  • @HenrikSchumacher Ah. I've never used Matlab. ;)
    – kirma
    Sep 14 at 13:06















One could also mention Piecewise in the context of If and Which...
– kirma
Sep 14 at 10:36




One could also mention Piecewise in the context of If and Which...
– kirma
Sep 14 at 10:36




1




1




@kirma Good point. I added it, but compared it to piecewise rather than to if. ;)
– Henrik Schumacher
Sep 14 at 12:03





@kirma Good point. I added it, but compared it to piecewise rather than to if. ;)
– Henrik Schumacher
Sep 14 at 12:03













Is IdentityMatrix[@,SparseArray]& intended to be IdentityMatrix[#,SparseArray]&? Might also be worthwhile to point out DiagonalMatrix, though I don't recall if there's a clear Matlab analog.
– eyorble
Sep 14 at 12:31




Is IdentityMatrix[@,SparseArray]& intended to be IdentityMatrix[#,SparseArray]&? Might also be worthwhile to point out DiagonalMatrix, though I don't recall if there's a clear Matlab analog.
– eyorble
Sep 14 at 12:31












@eyorble Good point. Corrected it. There are als diag and spdiags in Matlab.
– Henrik Schumacher
Sep 14 at 12:38




@eyorble Good point. Corrected it. There are als diag and spdiags in Matlab.
– Henrik Schumacher
Sep 14 at 12:38












@HenrikSchumacher Ah. I've never used Matlab. ;)
– kirma
Sep 14 at 13:06




@HenrikSchumacher Ah. I've never used Matlab. ;)
– kirma
Sep 14 at 13:06










up vote
9
down vote













When a language, e.g., Python, not emphasizing but has to talk about "functional programming", usually it speaks about three functions: map, filter and reduce. I always think comparison a good approach to learn things, so below I share the comparison I made before.



enter image description here



enter image description here



enter image description here



Besides, Function (&) vs lambda, Array, Table vs "list comprehensions" (Table has been mentioned but Range is redundant.).






share|improve this answer






















  • I think if you want to talk correspondence, the entirety of itertools is big. It provides a slew of utilities that Mathematica has, but does so in a more efficient lazy fashion.
    – b3m2a1
    12 hours ago














up vote
9
down vote













When a language, e.g., Python, not emphasizing but has to talk about "functional programming", usually it speaks about three functions: map, filter and reduce. I always think comparison a good approach to learn things, so below I share the comparison I made before.



enter image description here



enter image description here



enter image description here



Besides, Function (&) vs lambda, Array, Table vs "list comprehensions" (Table has been mentioned but Range is redundant.).






share|improve this answer






















  • I think if you want to talk correspondence, the entirety of itertools is big. It provides a slew of utilities that Mathematica has, but does so in a more efficient lazy fashion.
    – b3m2a1
    12 hours ago












up vote
9
down vote










up vote
9
down vote









When a language, e.g., Python, not emphasizing but has to talk about "functional programming", usually it speaks about three functions: map, filter and reduce. I always think comparison a good approach to learn things, so below I share the comparison I made before.



enter image description here



enter image description here



enter image description here



Besides, Function (&) vs lambda, Array, Table vs "list comprehensions" (Table has been mentioned but Range is redundant.).






share|improve this answer














When a language, e.g., Python, not emphasizing but has to talk about "functional programming", usually it speaks about three functions: map, filter and reduce. I always think comparison a good approach to learn things, so below I share the comparison I made before.



enter image description here



enter image description here



enter image description here



Besides, Function (&) vs lambda, Array, Table vs "list comprehensions" (Table has been mentioned but Range is redundant.).







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 14 at 11:09

























answered Sep 14 at 9:18









Αλέξανδρος Ζεγγ

2,264725




2,264725











  • I think if you want to talk correspondence, the entirety of itertools is big. It provides a slew of utilities that Mathematica has, but does so in a more efficient lazy fashion.
    – b3m2a1
    12 hours ago
















  • I think if you want to talk correspondence, the entirety of itertools is big. It provides a slew of utilities that Mathematica has, but does so in a more efficient lazy fashion.
    – b3m2a1
    12 hours ago















I think if you want to talk correspondence, the entirety of itertools is big. It provides a slew of utilities that Mathematica has, but does so in a more efficient lazy fashion.
– b3m2a1
12 hours ago




I think if you want to talk correspondence, the entirety of itertools is big. It provides a slew of utilities that Mathematica has, but does so in a more efficient lazy fashion.
– b3m2a1
12 hours ago










up vote
6
down vote













For those with experience in python, WRI has already provided a nice introductory tutorial along with many analogies.



However, for the class intended for image processing as mentioned by the OP, pure python is for certain not enough: numpy, pandas, scipy and pillow are some of the essential packages to go with.






share|improve this answer




















  • As someone who has used pillow a fair amount, I do tend to think it is less-intuitive and certainly less-powerful than Mathematica. It is nice to know that it exists and get some sense for how to use it for when you lose that academic Mathematica license and the cost is prohibitive, but as they say, "use the right tool for the job" and for maybe the first time ever, the right tool is Mathematica. I do enjoy numpy, though, as a stand in for Mathematica arrays. It is often much more efficient.
    – b3m2a1
    12 hours ago











  • @b3m2a1 Actually I was really reluctant to write up this post days ago as I love Mathematica to death. However, I feel helpless now and then if I want to communicate my research outcome with others in Mathematica. As long as WRI stays with their current business model, it is hopeless to see new blood flowing into the Mathematica usership, not to mention discipline-specific python packages are moving really fast : I personally interact with atmospheric models a lot and feel Mathematica lacks essential tools to deal with those tools.
    – sunt05
    11 hours ago











  • I won't deny any of that. Modern research is done is python (and some R and MATLAB) and Mathematica has decidedly abdicated its once considerable position in that. My sole argument was about image processing with Mathematica vs. pillow. In that specific case, Mathematica still outperforms python in usability and performance.
    – b3m2a1
    11 hours ago














up vote
6
down vote













For those with experience in python, WRI has already provided a nice introductory tutorial along with many analogies.



However, for the class intended for image processing as mentioned by the OP, pure python is for certain not enough: numpy, pandas, scipy and pillow are some of the essential packages to go with.






share|improve this answer




















  • As someone who has used pillow a fair amount, I do tend to think it is less-intuitive and certainly less-powerful than Mathematica. It is nice to know that it exists and get some sense for how to use it for when you lose that academic Mathematica license and the cost is prohibitive, but as they say, "use the right tool for the job" and for maybe the first time ever, the right tool is Mathematica. I do enjoy numpy, though, as a stand in for Mathematica arrays. It is often much more efficient.
    – b3m2a1
    12 hours ago











  • @b3m2a1 Actually I was really reluctant to write up this post days ago as I love Mathematica to death. However, I feel helpless now and then if I want to communicate my research outcome with others in Mathematica. As long as WRI stays with their current business model, it is hopeless to see new blood flowing into the Mathematica usership, not to mention discipline-specific python packages are moving really fast : I personally interact with atmospheric models a lot and feel Mathematica lacks essential tools to deal with those tools.
    – sunt05
    11 hours ago











  • I won't deny any of that. Modern research is done is python (and some R and MATLAB) and Mathematica has decidedly abdicated its once considerable position in that. My sole argument was about image processing with Mathematica vs. pillow. In that specific case, Mathematica still outperforms python in usability and performance.
    – b3m2a1
    11 hours ago












up vote
6
down vote










up vote
6
down vote









For those with experience in python, WRI has already provided a nice introductory tutorial along with many analogies.



However, for the class intended for image processing as mentioned by the OP, pure python is for certain not enough: numpy, pandas, scipy and pillow are some of the essential packages to go with.






share|improve this answer












For those with experience in python, WRI has already provided a nice introductory tutorial along with many analogies.



However, for the class intended for image processing as mentioned by the OP, pure python is for certain not enough: numpy, pandas, scipy and pillow are some of the essential packages to go with.







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 11 at 19:08









sunt05

1,4551019




1,4551019











  • As someone who has used pillow a fair amount, I do tend to think it is less-intuitive and certainly less-powerful than Mathematica. It is nice to know that it exists and get some sense for how to use it for when you lose that academic Mathematica license and the cost is prohibitive, but as they say, "use the right tool for the job" and for maybe the first time ever, the right tool is Mathematica. I do enjoy numpy, though, as a stand in for Mathematica arrays. It is often much more efficient.
    – b3m2a1
    12 hours ago











  • @b3m2a1 Actually I was really reluctant to write up this post days ago as I love Mathematica to death. However, I feel helpless now and then if I want to communicate my research outcome with others in Mathematica. As long as WRI stays with their current business model, it is hopeless to see new blood flowing into the Mathematica usership, not to mention discipline-specific python packages are moving really fast : I personally interact with atmospheric models a lot and feel Mathematica lacks essential tools to deal with those tools.
    – sunt05
    11 hours ago











  • I won't deny any of that. Modern research is done is python (and some R and MATLAB) and Mathematica has decidedly abdicated its once considerable position in that. My sole argument was about image processing with Mathematica vs. pillow. In that specific case, Mathematica still outperforms python in usability and performance.
    – b3m2a1
    11 hours ago
















  • As someone who has used pillow a fair amount, I do tend to think it is less-intuitive and certainly less-powerful than Mathematica. It is nice to know that it exists and get some sense for how to use it for when you lose that academic Mathematica license and the cost is prohibitive, but as they say, "use the right tool for the job" and for maybe the first time ever, the right tool is Mathematica. I do enjoy numpy, though, as a stand in for Mathematica arrays. It is often much more efficient.
    – b3m2a1
    12 hours ago











  • @b3m2a1 Actually I was really reluctant to write up this post days ago as I love Mathematica to death. However, I feel helpless now and then if I want to communicate my research outcome with others in Mathematica. As long as WRI stays with their current business model, it is hopeless to see new blood flowing into the Mathematica usership, not to mention discipline-specific python packages are moving really fast : I personally interact with atmospheric models a lot and feel Mathematica lacks essential tools to deal with those tools.
    – sunt05
    11 hours ago











  • I won't deny any of that. Modern research is done is python (and some R and MATLAB) and Mathematica has decidedly abdicated its once considerable position in that. My sole argument was about image processing with Mathematica vs. pillow. In that specific case, Mathematica still outperforms python in usability and performance.
    – b3m2a1
    11 hours ago















As someone who has used pillow a fair amount, I do tend to think it is less-intuitive and certainly less-powerful than Mathematica. It is nice to know that it exists and get some sense for how to use it for when you lose that academic Mathematica license and the cost is prohibitive, but as they say, "use the right tool for the job" and for maybe the first time ever, the right tool is Mathematica. I do enjoy numpy, though, as a stand in for Mathematica arrays. It is often much more efficient.
– b3m2a1
12 hours ago





As someone who has used pillow a fair amount, I do tend to think it is less-intuitive and certainly less-powerful than Mathematica. It is nice to know that it exists and get some sense for how to use it for when you lose that academic Mathematica license and the cost is prohibitive, but as they say, "use the right tool for the job" and for maybe the first time ever, the right tool is Mathematica. I do enjoy numpy, though, as a stand in for Mathematica arrays. It is often much more efficient.
– b3m2a1
12 hours ago













@b3m2a1 Actually I was really reluctant to write up this post days ago as I love Mathematica to death. However, I feel helpless now and then if I want to communicate my research outcome with others in Mathematica. As long as WRI stays with their current business model, it is hopeless to see new blood flowing into the Mathematica usership, not to mention discipline-specific python packages are moving really fast : I personally interact with atmospheric models a lot and feel Mathematica lacks essential tools to deal with those tools.
– sunt05
11 hours ago





@b3m2a1 Actually I was really reluctant to write up this post days ago as I love Mathematica to death. However, I feel helpless now and then if I want to communicate my research outcome with others in Mathematica. As long as WRI stays with their current business model, it is hopeless to see new blood flowing into the Mathematica usership, not to mention discipline-specific python packages are moving really fast : I personally interact with atmospheric models a lot and feel Mathematica lacks essential tools to deal with those tools.
– sunt05
11 hours ago













I won't deny any of that. Modern research is done is python (and some R and MATLAB) and Mathematica has decidedly abdicated its once considerable position in that. My sole argument was about image processing with Mathematica vs. pillow. In that specific case, Mathematica still outperforms python in usability and performance.
– b3m2a1
11 hours ago




I won't deny any of that. Modern research is done is python (and some R and MATLAB) and Mathematica has decidedly abdicated its once considerable position in that. My sole argument was about image processing with Mathematica vs. pillow. In that specific case, Mathematica still outperforms python in usability and performance.
– b3m2a1
11 hours ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181499%2fanalogies-to-help-new-users%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay