Thisisanarchivaldumpofoldwikicontentseescipy.orgforcurrentmaterial.
Pleaseseehttps://docs.scipy.org/doc/numpydev/user/numpyformatlabusers.html
Contents
1.Introduction
2.SomeKeyDifferences
3.'array'or'matrix'?WhichshouldIuse?
1.Shortanswer
2.Longanswer
4.FacilitiesforMatrixUsers
5.TableofRoughMATLABNumPyEquivalents
1.GeneralPurposeEquivalents
2.LinearAlgebraEquivalents
6.Notes
7.CustomizingYourEnvironment
8.MATLABpackages/toolsandequivalentforusewith
NumPy
9.Links
Introduction
MATLAB®and!NumPy/!SciPyhavealotincommon.Buttherearemanydifferences.NumPyandSciPywerecreated
todonumericalandscientificcomputinginthemostnaturalwaywithPython,nottobeMATLAB®clones.Thispageis
intendedtobeaplacetocollectwisdomaboutthedifferences,mostlyforthepurposeofhelpingproficientMATLAB®
usersbecomeproficientNumPyandSciPyusers.NumPyProConPageisanotherpageforcuriouspeoplewhoare
thinkingofadoptingPythonwithNumPyandSciPyinsteadofMATLAB®andwanttoseealistofprosandcons.
SomeKeyDifferences
InMATLAB®,thebasicdatatypeisa
multidimensionalarrayofdoubleprecision
floatingpointnumbers.Mostexpressionstakesuch
arraysandreturnsucharrays.Operationsonthe2
Dinstancesofthesearraysaredesignedtoact
moreorlesslikematrixoperationsinlinear
algebra.
InNumPythebasictypeisamultidimensionalarray.
Operationsonthesearraysinalldimensionalitiesincluding2D
areelementwiseoperations.However,thereisaspecialmatrix
typefordoinglinearalgebra,whichisjustasubclassofthe
arrayclass.Operationsonmatrixclassarraysarelinear
algebraoperations.
MATLAB®uses1(one)basedindexing.The
initialelementofasequenceisfoundusinga(1).
Seenote'INDEXING'
Pythonuses0(zero)basedindexing.Theinitialelementofa
sequenceisfoundusinga[0].
MATLAB®'sscriptinglanguagewascreatedfor
doinglinearalgebra.Thesyntaxforbasicmatrix
operationsisniceandclean,buttheAPIforadding
GUIsandmakingfullfledgedapplicationsismore
orlessanafterthought.
NumPyisbasedonPython,whichwasdesignedfromthe
outsettobeanexcellentgeneralpurposeprogramming
language.WhileMatlab'ssyntaxforsomearraymanipulations
ismorecompactthanNumPy's,NumPy(byvirtueofbeingan
addontoPython)candomanythingsthatMatlabjustcannot,
forinstancesubclassingthemainarraytypetodobotharray
andmatrixmathcleanly.
InMATLAB®,arrayshavepassbyvalue
semantics,withalazycopyonwriteschemeto
preventactuallycreatingcopiesuntiltheyare
actuallyneeded.Sliceoperationscopypartsofthe
array.
InNumPyarrayshavepassbyreferencesemantics.Slice
operationsareviewsintoanarray.
InMATLAB®,everyfunctionmustbeinafileof
thesamename,andyoucan'tdefinelocal
functionsinanordinaryscriptfileoratthe
commandprompt(inlinesarenotrealfunctions
butmacros,likeinC).
NumPycodeisPythoncode,soithasnosuchrestrictions.You
candefinefunctionswhereveryoulike.
MATLAB®hasanactivecommunityandthereis
lotsof codeavailableforfree.Butthevitalityof
thecommunityislimitedbyMATLAB®'scost;
!NumPy/!SciPyalsohasanactivecommunity,basedrighthere
onthiswebsite!Itissmaller,butitisgrowingveryquickly.In
contrast,Pythonprogramscanberedistributedandusedfreely.
SeeTopical_Softwareforalistingoffreeaddonapplication