We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

NumPy (1/2)

00:00

Formal Metadata

Title
NumPy (1/2)
Title of Series
Number of Parts
43
Author
Contributors
License
CC Attribution 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language
Production PlaceErlangen, Germany

Content Metadata

Subject Area
Genre
5
Thumbnail
1:34:10
33
Thumbnail
1:31:57
34
Thumbnail
1:28:12
35
Thumbnail
1:27:32
41
Thumbnail
1:31:21
43
Array data structureLibrary (computing)VotingPlastikkarteFactory (trading post)Multiplication signData managementHypermediaRow (database)MereologyPresentation of a groupVideo gameFamilyTerm (mathematics)DatabasePhysicistComputer clusterPoint (geometry)NeuroinformatikStudent's t-testInterrupt <Informatik>BitTask (computing)LaptopNatural numberComputing platformImage processingComputer animation
Presentation of a groupArray data structureControl flowComputer networkProbability density functionLaptopCodeElectronic mailing listVirtual machineLaptopWindowPhysical systemDirectory serviceArmMultiplication signOperator (mathematics)AdditionDistribution (mathematics)WebsiteGoodness of fitSystem callComputer animation
Expert systemSource codeProbability density functionWeb pageElectronic design automationLevel (video gaming)Numerical analysisInterior (topology)Image registrationControl flowLaptopCodeComputer networkComa BerenicesCloningSign (mathematics)Distribution (mathematics)Computer-generated imageryArray data structureSoftware developerComputer programmingPhysical systemBasis <Mathematik>Matrix (mathematics)AdditionCalculationRevision controlRepresentation (politics)MultiplicationCellular automatonMetadataLetterpress printingData typeComputer programmingWeb pageRow (database)LaptopLink (knot theory)Sheaf (mathematics)BitFerry CorstenMultiplication signShared memoryMoment (mathematics)Order (biology)Operating systemWeb browserFormal languageWordAreaRule of inferenceCausalitySign (mathematics)Uniformer RaumState of matterGoodness of fitPosition operatorComputer animation
Array data structureElectronic mailing listLoginMedical imagingResultantProcess (computing)AuthorizationMetropolitan area networkData storage deviceComputer fileDirectory serviceLaptopRadical (chemistry)Web pageWindowWeb browserComputer programmingType theoryElectronic mailing listMenu (computing)Different (Kate Ryan album)Computer animation
Electronic mailing listGroup actionComputer fileArray data structurePower (physics)DataflowArray data structureDirectory serviceWindowLaptopInterior (topology)CodeMultiplication signWeb pageBitData typeCellular automatonNumberRight angleArmRule of inferenceCopyright infringementFilm editingMereologyDigital photographyComputer animation
Library (computing)Standard deviationData structureMathematical analysisFundamental theorem of algebraVideo game consoleInteractive televisionLibrary (computing)Connectivity (graph theory)Array data structureCodeGastropod shellMereologyTask (computing)Medical imagingFunctional (mathematics)Basis <Mathematik>Electronic program guideLie groupTouchscreenLattice (order)Multiplication signAreaMoving averageScalable Coherent InterfaceMilitary baseSign (mathematics)Computer animation
MaizePresentation of a groupElectronic mailing listCellular automatonMetadataSource codeCodeProgram slicingRandom numberTape driveLevel (video gaming)Expert systemNumerical analysisProbability density functionWeb pageRootBuildingText editorSource codeBitWeb pageReading (process)Entire functionGroup actionLevel (video gaming)Electronic program guideInformationWebsiteFile formatSheaf (mathematics)Right angleSystem callPoint (geometry)Moment (mathematics)Computer animationSource code
Digital object identifierInterior (topology)Expert systemSource codeProbability density functionLevel (video gaming)Web pageCodeNumerical analysisComputer-generated imageryMatrix (mathematics)Linear mapAlgebraFormal languageSign (mathematics)Regular graphMoment (mathematics)Object (grammar)Archaeological field surveyMedical imagingCodeGreen's functionArray data structureData storage deviceMatrix (mathematics)Vector spaceContext awarenessLinear algebraDimensional analysisBitGraph coloringMultiplication signEigenvalues and eigenvectorsDirection (geometry)CalculationMathematicianArithmetic meanFlow separationBit rateParadoxComputer animation
Subject indexingCountingNegative numberPrice indexElectronic mailing listObject (grammar)Moment (mathematics)LaptopInternational Date LineMultiplication signConnected spaceCuboidComputer configurationArithmetic meanConfidence intervalDifferent (Kate Ryan album)Rule of inferenceNumberProduct (business)Subject indexingProgram slicingElectronic mailing listPoint (geometry)Element (mathematics)Boolean algebraStandard deviationSimilarity (geometry)String (computer science)Category of beingArray data structureType theoryComputer animation
Computer multitaskingElement (mathematics)Electronic mailing listProgram slicingElement (mathematics)NumberObject (grammar)Real numberFilm editingBitInformationTerm (mathematics)Point (geometry)Flow separationVotingThomas BayesGame controllerLie groupPhysical lawWebsiteArithmetic meanComputer animation
Pell's equationMatrix (mathematics)Presentation of a groupCodeLevel (video gaming)Web pageElectronic mailing listUser interfaceSign (mathematics)Product (business)Cellular automatonAuthorizationShift operatorBridging (networking)Wave packetExecution unitElectronic mailing listNumberRange (statistics)Frame problemComputer animation
Electronic mailing listVideoconferencingShift operatorWebsiteView (database)FamilyVideo gameMultiplication signRootElectronic mailing listCellular automatonProgram slicingPoisson-KlammerBitFrame problemNumberFunction (mathematics)Film editingMoment (mathematics)ExpressionExecution unitComputer animation
Matrix (mathematics)User interfaceHacker (term)Program slicingOpen setMultiplication signMereologyCASE <Informatik>RootSoftware development kitDecision theoryRoundness (object)Inheritance (object-oriented programming)Electronic mailing listArithmetic progressionElement (mathematics)Asynchronous Transfer ModePersonal digital assistantBlock (periodic table)Computer animation
Matrix (mathematics)Program slicingMatrix (mathematics)Electronic mailing listQuicksortRow (database)Group actionShape (magazine)Basis <Mathematik>Cellular automatonOrder (biology)Object (grammar)Element (mathematics)Subject indexingDevice driverSocial classMedical imagingData miningRational numberRight angleVideo gameMetropolitan area networkComputer animation
Matrix (mathematics)Program slicingNumberMatrix (mathematics)Electronic mailing listElement (mathematics)Message passingRow (database)Point (geometry)AsymmetryObject (grammar)Arithmetic meanSubject indexingVideo gameMultiplication signDisk read-and-write headComputer animation
Matrix (mathematics)Electronic mailing listObject (grammar)Element (mathematics)Read-only memoryData structureMatrix (mathematics)Row (database)Electronic mailing listNeuroinformatikObject (grammar)Semiconductor memoryAsymmetryElement (mathematics)HypothesisTerm (mathematics)Multiplication signFood energyComputer programmingAreaResultantDifferent (Kate Ryan album)Speech synthesisGroup actionComputer configurationComputer animation
String (computer science)Object (grammar)Computer configurationBit rateIncidence algebraTerm (mathematics)Trigonometric functionsModule (mathematics)SineTangentNichtlineares GleichungssystemLibrary (computing)Symbol tableMathematicsFunctional (mathematics)BitType theoryForcing (mathematics)Process (computing)CodePoint (geometry)Electronic mailing listMultiplication signSign (mathematics)Lie groupMetropolitan area networkKey (cryptography)Figurate numberOptical disc driveFocus (optics)Computer animation
Matrix (mathematics)User interfaceAttribute grammarRadio-frequency identificationArray data structureFile formatLetterpress printingType theoryDefault (computer science)IntegerBoolean algebraUnicodeString (computer science)Object (grammar)Group actionComputer configurationString (computer science)IntegerDefault (computer science)Complex numberType theoryArray data structureComputer animation
Radio-frequency identificationArray data structureAttribute grammarLetterpress printingFile formatOnline helpUser interfaceType theoryDefault (computer science)IntegerBoolean algebraUnicodeString (computer science)Metropolitan area networkTerm (mathematics)IntegerDegree (graph theory)Point (geometry)NeuroinformatikArray data structureOrder (biology)Type theoryError messageComputer programmingEvent horizonSelf-organizationComputer animation
Variable (mathematics)Radio-frequency identificationArray data structureOnline helpFile formatLetterpress printingPartition (number theory)MiniDiscoutputOpen setRead-only memoryLaptopBinary fileModule (mathematics)Core dumpFunction (mathematics)Interface (computing)Parameter (computer programming)Pointer (computer programming)Maxima and minimaElectronic mailing listArray data structureFunctional (mathematics)Order (biology)Magnetic stripe cardFrequencyService (economics)InformationDampingMatrix (mathematics)Coefficient of determinationString (computer science)Variable (mathematics)Online helpGroup actionDefault (computer science)InferenceType theoryObject (grammar)Complex numberData typeInheritance (object-oriented programming)NumberWebsiteMultiplication signPoint (geometry)Shape (magazine)Computer configurationOffice suiteComputer animation
Matrix (mathematics)Program slicingUser interfaceRadio-frequency identificationVariable (mathematics)MassModule (mathematics)Function (mathematics)Core dumpPartition (number theory)Pointer (computer programming)outputParameter (computer programming)Interface (computing)Maxima and minimaArray data structureType theoryShape (magazine)Object (grammar)File formatLetterpress printingData typeAttribute grammarBitElectronic mailing listVideo gameFunctional (mathematics)SequenceType theoryArithmetic meanRange (statistics)Attribute grammarArray data structureElement (mathematics)Revision controlRule of inferenceRAIDRow (database)Bit rateDifferent (Kate Ryan album)Operator (mathematics)Inheritance (object-oriented programming)Computer animation
Attribute grammarArray data structureQuantum stateShape (magazine)Type theoryBoolean algebraFile formatLetterpress printingUser interfaceStatement (computer science)String (computer science)Element (mathematics)Category of beingKognitionswissenschaftPersonal identification numberDefault (computer science)Physical systemRevision controlDifferent (Kate Ryan album)Electronic mailing listNumberAttribute grammarObject (grammar)TupleBitOrder (biology)Dimensional analysisMatrix (mathematics)Semiconductor memoryData typeArray data structureRandom variableCellular automatonMathematicsStreaming mediaComplex (psychology)Interior (topology)IntegerState of matterNeuroinformatikRule of inferenceVector spaceCache (computing)Graph (mathematics)Maxima and minimaAngleMultiplication signShooting methodNormal (geometry)Computer configurationVideo gameSocial classBit rateLevel (video gaming)Decision theoryText editorVirtual machineSound effectCausalityFigurate numberGoodness of fitComputer animation
Attribute grammarStatement (computer science)String (computer science)Quantum stateArray data structureType theoryBoolean algebraBoolean algebraSemiconductor memoryStreaming mediaDifferent (Kate Ryan album)Electronic mailing listComplex numberMereologyMultiplication signData typePosition operatorNumberOffice suiteComputer animation
Statement (computer science)Array data structureAttribute grammarType theoryBoolean algebraString (computer science)Quantum stateSeries (mathematics)ResultantRange (statistics)Multiplication signBoolean algebraString (computer science)Point (geometry)LengthDampingCASE <Informatik>Streaming mediaObject (grammar)Right angleComputer animation
LaptopStatement (computer science)RoutingDecision theoryFocus (optics)CausalityTelecommunicationMultiplication signCalculationVariable (mathematics)NeuroinformatikNumberStandard deviationPoint (geometry)Right angleComputer animation
Type theoryDefault (computer science)IntegerBoolean algebraUnicodeString (computer science)Statement (computer science)IntegerBitMaxima and minimaQuicksortMultiplication signCASE <Informatik>Revision controlComputer configurationData typeObject (grammar)Representation (politics)VotingVideo gameInheritance (object-oriented programming)CausalityProcess (computing)Computer animation
Statement (computer science)Right angleNumberPoint (geometry)Office suiteMoment (mathematics)Computer configurationSemiconductor memoryMatrix (mathematics)Array data structureData storage deviceDimensional analysisElement (mathematics)Object (grammar)Different (Kate Ryan album)TupleGoodness of fitView (database)SpacetimeMultiplication signComputer programmingBitOperating systemArmWordComputer animation
MathematicsMatrix (mathematics)Element (mathematics)Element (mathematics)Matrix (mathematics)Extension (kinesiology)Direction (geometry)TupleGroup actionComputer configurationComputer animation
Statement (computer science)Attribute grammarArray data structureRadio-frequency identificationDigital object identifierShape (magazine)Letterpress printingFile formatUser interfaceType theoryString (computer science)System calloutputQuantum stateGroup actionDimensional analysisRing (mathematics)Shape (magazine)Computer animation
Shape (magazine)Matrix (mathematics)Element (mathematics)MathematicsUser interfaceAttribute grammarRight angle2 (number)Semiconductor memoryElement (mathematics)Price indexPosition operatorBinary multiplierQuantum mechanicsMatrix (mathematics)GradientComputer animation
Shape (magazine)Attribute grammarLaptopMatrix (mathematics)CoroutineHill differential equationGrand Unified TheoryUser interfaceMatrix (mathematics)Semiconductor memoryAttribute grammarDifferent (Kate Ryan album)Type theoryView (database)Escape characterRow (database)Direction (geometry)Cellular automatonElement (mathematics)Point (geometry)MultiplicationString (computer science)Right angleMultiplication signOperator (mathematics)Revision controlNeuroinformatikInterface (computing)Line (geometry)MathematicsElectronic mailing listCalculationGroup actionState of matterComputer configurationRule of inferenceFocus (optics)Bit rateBitOffice suiteStreaming mediaGame theoryMaizeTouchscreenRepresentation (politics)Computer animation
Element (mathematics)MathematicsMatrix (mathematics)Numerical analysisRandom numberNumberCoroutineBit rateMultiplication signSpacetimeComputer configurationControl flowElement (mathematics)Electronic mailing listArray data structureEvent horizonRankingPoint (geometry)Motif (narrative)BitThomas BayesWebsiteHypermediaInheritance (object-oriented programming)Direction (geometry)Machine visionComputer animation
Musical ensembleCoroutineRange (statistics)Point (geometry)Structural loadDataflowCASE <Informatik>GradientBounded variationComputer animation
CoroutineMusical ensembleBuildingDesign by contractCivil engineeringPower (physics)Survival analysisRegular graphSpacetimePoint (geometry)Error messageNumberElement (mathematics)BitTrailElectronic mailing listComputer animation
Musical ensemble2 (number)Video game consoleScaling (geometry)NumberCausalityWordMereologyOrder (biology)RootSimulationMultiplication signSquare numberMilitary basePoint (geometry)LogarithmComputer animation
Plot (narrative)User interfaceLine (geometry)IntegerModule (mathematics)MereologyLaptopProjective planeDirection (geometry)Representation (politics)Standard deviationOrder (biology)Cartesian coordinate systemCodeElement (mathematics)Loop (music)Trigonometric functionsCalculationPoint (geometry)Parameter (computer programming)CircleMultiplication signOvalWater vaporSystem callGroup actionConnectivity (graph theory)Computer animation
Computer animation
Transcript: English(auto-generated)
So let me first introduce myself. My name is Gerd Ingold. I'm a theoretical physicist from the University of Augsburg. I got introduced to Python almost 15 years ago by a graduate student who I'm very grateful to,
because nowadays I'm using Python almost everything I'm doing, scientific work, and database work, vectoring works, and whatsoever. So Python is really a platform which you can use for almost every task in computing. And today I'll tell you about Noombi arrays,
at least from the introductory level, which is something which you'll need by now to do in scientific work. Now having introduced myself a little, I would like to know a little bit more about you. I saw some of the faces this morning in the tutorial. Who has been in the tutorial this morning?
Almost everybody. So probably basically everything which was taught this morning. I will come back to a few points during this tutorial, because such a tutorial is not enough to really do things in detail. Who has thought about Python for the first time,
or has been using Python for the first time this morning? OK. So it's nice that you came here, and I hope that after this tutorial you're convinced that Python is really useful for your work.
How many of you are, let's say, natural scientists, engineers? Quite a few. But probably usually there are some people from, oh, there's somebody from humanities. Yeah? OK. Somebody else outside the natural sciences engineering?
Even for these people, I think it would be very useful for example in image processing. We'll come to that maybe during the tutorial. One more important point. Please interrupt me if you have any questions. Interrupt me right away. I have a certain amount of material prepared for this afternoon.
If I don't finish, it's not so important. The important point is that you profit from what I'm teaching. So please interrupt me. My experience from teaching is that if somebody of you asks a question, it's very likely that somebody else wanted to ask the same question,
but simply didn't dare to ask. So you do yourself a favor, and you do others a favor. So please feel free to interrupt me at any time. Now, we'll have a presentation which you'll find online, but there's also a Jupyter notebook.
This one here, and this one here. Now, who hasn't installed this notebook yet? OK, there are quite a few. I'll say something about that in a minute. Who does not have a Tizen NumPy installation?
Everybody? OK, so there's Michael who is going to help. I've brought the anaconda distribution, which I would recommend to everybody doing scientific work on these USB sticks. It's a lot of material to download.
So what you do on this USB stick, you just go to the directory, depending on the operating system. This is Linux Mac or Windows. And then you go to 32-bit or 64-bit, depending on the machine. And you should be able to install it. Otherwise, it's not going to help you.
About the Jupyter notebook, I think it's important that you are able to follow what I'm doing here in the notebook. So you should, if possible, download it. If it's not possible for some reason, just try to team up with a neighbor. So at least two of you can share
working on one notebook, and otherwise you don't want it as much as possible. So how do you get the notebook? Well, one thing you can do is you can go to the program of this conference. You probably know this page. So you go to Europsych.io 2017
to the program. And on this program page you have the installation instructions for tutorials. And if you go there, you should see this page here. And if you scroll a little bit down,
you have this section on Numpy. And all the way down here there's this link to the notebook which I'm going to use in the exercises. So you just click on it, get the notebook, and then with a right-click
you should be able to save this page. This might look different on your operating system. You should be able to download this Jupyter notebook and hopefully load it and then the Jupyter notebook broke.
Does everyone who hasn't downloaded the notebook get able to get to this page? Just let me know if there's any problem. I'll give you a couple of minutes to download the notebook.
I mean, if there's a problem with the Wi-Fi and you're unable to download the notebook, just keep up with the neighbor.
Hey. So are you all able to access the notebook
or is there a problem somewhere? The notebook is very small actually. Yeah. I mean, otherwise if your neighbor has the notebook just
keep up and I mean, actually if you're working in a team that might even be better because you can discuss possible solutions. You might have ideas, sharing ideas when trying to code. This is not a bad idea.
So is everybody more or less in the situation that we can get started or do we need more time? Okay. Nobody's answering too fast so I see you're ready. Okay, let's No? Okay. So what's the problem? Are you still having something that I can find out?
This takes some time because this is the alarm one still has the notebook there or just the notebook here? The notebook? The notebook? Okay. Just give it some time. Mika will be passing around using the notebook.
I suggest that just pass it on. Pass it. Could you change this? This just takes time but maybe you can clear out for a moment. But this should work
Okay. I think we we should get started and please if you still have a problem take your hand and we will look out for you take the next one
and then I think we will take this language Okay. So in order to get the notebook running what you need to do depending on your operating system you need to install the Jupyter notebook the Jupyter notebook will
bring up a page on your internet browser which should look like this So what you do is
if you are in Linux you open a terminal you type in jupyter-notebook if you are on Windows or Mac you have more light in your menu
or Mac you can also use the on Windows you probably have a menu of different programs and you just select the Jupyter notebook sometimes it's useful to have your browser started before and then you should come to a page which more or less looks like this
some kind of list of files in the directory and if you are starting this in the directory where you have the notebook store then you can select this and just by clicking on it you can start the notebook So let me
do this for you just to see how it works and stop this So hopefully you will be able to get into such a situation where you just click
on the notebook then another window will pop up it takes a second until this really gets started and then you should be able to see these comments and some cells that you can put in code
later on Is this working more or less for most of you? No What's not working? Where are you stuck? You cannot open it so that means you
get into this page And you see the notebook or you don't see it? That is in the wrong directory You have to You are on Windows? You can just try to open it there Right
Somebody else did major problems? Does anyone still need the Jupyter notebook? Yes or no?
Just for downloading the Jupyter notebook Ok Since you have done already this introductory work probably I don't need to convince you anymore
that you should stay in this tutorial because you have spent so much time on getting prepared that you are going to stay anyway but nevertheless maybe I should tell you why NumPy arrays should be interesting at all Why are you going to spend three hours in a tutorial on something I mean this should be worth it
I mean what's NumPy arrays about? Actually this morning in the tutorial you already heard a bit about NumPy, NumPy Ints special data types and so on Well actually whenever you do scientific work then you are using NumPy in some way or the other
Actually Python was mentioned this morning but at the very end in this morning's tutorial it was said that there are a lot of components in the standard library So a lot of things which usually you would like to code are already present People say Python comes with batteries
included in it You know this, on a Saturday you buy this toy and you come home and you want to try it out and you realize that there are no batteries and you cannot try it out nor on Saturday evening nor on Sunday That's of course not nice
and the nice thing about Python is that these batteries are included All this is for free NumPy is for free which is not trivial for scientific library A lot of effort goes in all of these packages and actually for people who are interested in that on Friday there will be
what you would call a sprint where you can contribute to the packages if you are interested So the question for us as scientists is what about the batteries for scientists? Are there ESSO functions? Can I do linear algebra? Can I do image processing?
Can I do data analysis? and so on And there is what people call the scientific Python ecosystem or sometimes the scientific Python stack which consists mainly of NumPy or the basis and then the
SciPy library including the SciKits much here and here about Scikit-learn, Scikit-image and so on Arctotlip, the iPy shell SwingPy, Pandas and some more packages And all of these packages when you are using them or when you are attending other tutorials there will be tutorials on Arctotlip, on SciPy
tomorrow on SwingPy Pandas as well All of these packages rely basically on the functionality which SwingPy provides, namely the NumPy arrays Well, the NumPy provides much more as you will see but the most important part are really
the NumPy arrays And so my task during this tutorial is basically to tell you how these NumPy arrays and so-called NT arrays really work Now, if you want to do some reading by your own after this tutorial and you want to learn a bit more about all these things
and really use them there are two very important sources well, the web page with the NumPy tutorial sorry, with the NumPy documentation which you here
so docs.scipi.org So you can go to the NumPy reference guide and here you have a lot of material where you find everything documented which you need to know So that's the source of information
a very important source of information and the second quite important source of information are the SciPy lecture notes and if you look at who contributed you will see that quite a few people this guy is under
for example Gael and Emmanuel are around here Emmanuel is the one with the baby so you will recognize him So these people who are doing this work for you they are actually present you can talk to them and if you want to contribute
to these lecture notes for the moment for you the important point is that in these lecture notes you find really a lot of material on the Python language on NumPy, on Microsoft SciPy and so on So this is a very valuable resource if you really want to use all these tools
Now, what do we want to do? Well, as scientists we want to work with vectors and matrices the objects we are mostly used to and if I say scientists you as well
because you might have to do with images maybe I don't know, not so much no, ok, so maybe I have to do with arrays anyway but I want to point out that for example a color image is also an array I mean as a mathematician
you might not think about this as an array in the first place but an image is nothing else an actual image is nothing else than an array n times n times 3 that's a third direction red, green, green So there is a lot of objects which can
really be very well represented as vectors or matrices matrices in higher dimensions If you want you can use ten dimensional matrices but be aware if you have a ten dimensional matrix, thousand by thousand by thousand by thousand it's going to be very huge I still need a storage
What we want is that our code runs fast. Some people say that Python tends to be a bit slow actually using numpy will improve the speed of your code considerably if you do a trial You would like to have support for linear algebra but be able
to calculate eigenvalues or eigenvectors of the matrix or something like that There are a lot of things we want to do with matrices and that's really where numpy comes in And at that point you might think, well this morning I thought about lists a lot in the tutorial this morning
you might have thought about lists anyway Lists are a means of collecting objects in this list and addressing individual objects in this list And the main difference between a list a Python list and the numpy arrays that in a Python list
you can put arbitrary objects This morning you have seen that in a list you can have numbers, you can have strings at the same time or even other lists So this is a multi-purpose collection and collects anything which you want to put in there
Whereas an array or the array we are thinking about is really something homogeneous where all the data are basically of the same type And that's where the big advantage lies That's what we are going to use and that's what will make things fast in the end Now there's one similarity or one connection
between arrays and lists which I want to discuss here or remind you of properties of lists That's the way one indexes individual list elements or slices which you have seen this morning So we'll try this out in a second
but let me just remind you of the main points So suppose you have a list of objects This is now the standard Python list It's not about the PyArrays for the moment but you will see that following PyArrays it works in the same way and you have objects We learned this morning that the objects start with index 0
100 to 400 So they start at 0, 1, 2 and so on and the nice thing in Python is you can number the elements also from the back minus 1, minus 2, minus 3, 1, 2, minus 3 and then you can also
use slices and whoever attended the tutorial this morning you might have been maybe a bit surprised that if you write something like that suppose I do this a from 0 first element to 5 you might have been surprised that
5 is not included Ok, now at this point you can learn the last element is not included which is not very convincing So think of this in terms of real slices So this is cut 0 this is cut 1 this is cut 2, 3, 4, 5 and if you cut here the fifth cut here
will be between 4 and 5 Now it's obvious that the slice from 0 to 5 will stop at element 4 It's really a slice you're not numbering the individual objects and the nice thing about it is that you can continue with the same number
you don't have to add one That's the idea of the slices such as slicing such as slice will contain several pieces of information the start, the stop and the step size So you can step in steps of 2
you can even have negative steps you can go from backwards to forwards you can leave out these elements if you leave out the start that means the slice will start at the beginning if you leave out stop it will go all the way until the end if you leave out the step then the step size might be all the way
but you can control all these drawings Ok and that's now the sign whenever you see this sign that's where you have to do something So you go to your book
Is this readable for everybody or should I enlarge it even further? Can you read this in the back?
So what you can do is you can click on such a such a cell now if you click on it you see this is going to be green if it's green it means you can change things so be aware so if I start typing here as soon as the frame is green you're going to change
what's written there but of course that's what you're supposed to do and now you can just say shift enter and you should get a list Ok, does that work for everybody?
Just shift enter I use shift enter because then you get immediately onto the next cell here So what has happened here? Well, I said range of 10 range of 10 actually in Python 3 generates you numbers on demand
generates the numbers from 0 to 9 and list just says put these numbers from me into a list which I call my list and I print it and that's the list from 0 to 9 Now if you click on this just in the mighty things happening
if you click on this then you could change the text here as well but that's something you probably don't want to do so just with the shift enter everything will be fine again and now for the moment we have this variable my list which is this list
from 0 to 9 and let's just practice a bit of slicing So what I would like to ask you is to in these cells here fill in the corresponding slicing So you should put this expression here
which as the output produces the list which I have indicated here So let's do the first example together maybe So you go in this cell you click on it you have a green frame so now you can enter something you want to do a slice of my list my list
brackets and now we want to start at 2 start at 2 and we want to have 5 in unit so we have to cut between 5 and 6 that's the cut number 6 so 26 and that's right
and now I would like to ask you to in these few examples I'll give you a couple of minutes please try to reproduce the list which I've given there if I have to make the examples if there's any problem
just tell me and in 1 or 2 minutes I'll go through these examples and show you how it is working between this there's somebody
needing any proper assistance in setting up things try to
see
everything in progress as expected Did anybody encounter any problems? Was one of the examples obviously difficult? Sorry? Okay, yeah you don't have to do that
that's the interesting part okay let's start here there are actually several solutions you could either say let's start explicitly at 0 or as I told you omitting the starting value means we start at 0 so it's sufficient to just say colon 5
but if you say 0 colon 5 it's also fine it's just more explicit then here's 689 start at 6 and go to the very end so I don't need to know how long the list is that's actually the situation which is much more
important you always know that the list starts at 0 so putting the 0 here is easy but often you don't know how long the list is of course you have seen this morning that you can ask the list how long are you but that's unnecessary in this way you get the list to its very end
and this one here this is basically the full list I put colon colon from the beginning to the end in steps of 2 and now we come to this interesting example back blocks this is minus 1
because minus 1 is the step minus 1 goes back blocks starting at 9 8 and so on and finally 7 5 3 7
2 oh sorry actually if something like this happens then you're in this mode to enter this text here just hit enter and you're fine if I have step 2 then I of course go forward
from the element 7 forward there's nothing left if I want to go to 2 so you have to go backwards to minus 2 ok are there any questions at this point?
very good because we're going to use the sizing later on in the new high eraser now now let's for the moment ask do we really need the high eraser? I mean there's this idea that
maybe we can use matrices in this way that we say ok a matrix is a sort of list we could say each row here is a list and the whole matrix is a list of lists so I could define a matrix
at least that's something you could imagine I could define a matrix as a list which starts here and ends here and which contains the 3 rows as lists ok so the question is can we extract a row from this list? and can we extract the code?
let's see so I have defined the matrix for you now in order for this to work you need to execute this cell here otherwise the object matrix is not defined so you just execute it and now let's see give you
a minute to try to do a slicing in order to extract let's say the second row and see what we are able to manage if you finish this class then you can try to extract the second column by slicing
please don't use list comprehensions we heard this morning about list comprehensions but don't use them here
anybody find a solution for the first problem? or have you got the second row? any idea? the second element, right? and how would you index it?
the way I did, the matrix matrix 1 matrix 1, right? so this works the second row it's just the second element of the matrix, now this is sort of asymmetric, if you have matrices in mind it would sort of be nicer to say
and that's, of course I will use a useless driver for this but let me just add this one here the idea is ok, I have a matrix of 1, which is the number of the row and I use all the elements in this list, I just write down
this explicitly at this point you wouldn't never do this in this way, but let me do this just to make the point of a matrix I mean, making rows and columns more symmetric now, given that you might think that you could get
a column in the following way it's a stupid idea, but I mean why not try it? I will interchange rows and columns right? what happens? you get the same thing can we understand this?
of course we can, I mean Biden doesn't do something just out of fun he's doing this for a good reason so what is matrix colon? well, colon means everything from the beginning to the end so now this is like a pass taken this morning
it doesn't do anything it just returns the full list and then as you said, index number 1 tells us out of this full object here, I get the element number 2 so I'm back to the second row so I don't get columns out easily and that already tells you that
there's something wrong with lists they don't really work for matrices you cannot access a column easily you can do this with list comprehensions if you want but I mean that's completely asymmetric I mean as a scientist you would never accept something as asymmetric as one would
need to do here ok, so you can expect a row easily but you cannot expect a column and that means lists of lists just do not go like matrices they are not good matrices so what are the problems?
well, we have seen that different axes cannot be treated on equal footing there was the problem that lists can contain arbitrary objects and this typically makes lists slow because Python never knows where the next object comes from it has ways to look it up of course
but it's not that it knows that every 8th byte or so there is the next object it really has to do some look up to do that lists elements can be actually handled in memory so it's not like Python could just go through the memory and operate on the elements so all of these are coins
which make lists relatively slow and we said we want to do our computation fast it's fine, we often have problems which need some computing time and it makes a difference in particular if you need to finish your master thesis within a few months then it's important that
the problem runs fast enough but even more important if you think in terms of matrices lists are conceptually inappropriate let's see this asymmetry between rows at home and they have much less performance than possible performance uses
so we have to do something better and what is better? that's the NP array and the NP array is basically short for n-dimensional array or multidimensional array so this is an array of homogeneous objects all the same, all floats, all integers or whatever, even strings
of fixed size items all these integers all these floats, all these strings we experimented that in a minute are all of the same size so we have seen this morning that sometimes you have to import something into Python
and there are actually different ways to import a package often people do the following, don't do this now because I don't recommend this so what often people do, for example if you import the math module if you want to use sine, cosine, tangent and whatever
people do this actually from math in Pakistan the problem is that you import all symbols out of this package and this can be really bad if this is a huge package and you have lots of symbols in particular it will turn out that this numpy
package, for example contains its own sine function and cosine function now suppose you import from math everything and from numpy everything then you ask yourself what is the sine actually, is it the sine from the math library or from the numpy library
and here with numpy you really get lots of symbols so don't do that so the other option would be to say okay, I need a race I need sine, cosine that's fine but in reality it's not very practical if you need
lots of functions out of this library so you don't want to have a long list of such objects here so that's what you typically don't do then the option would be to say numpy this forces you at every point where you use a numpy function to say numpy dot
something which is annoying well it's nice because you say this comes from numpy it's real, this sine function or cosine comes from numpy but still you have to type numpy which is a bit long so let's make it true why? because everybody
does it this way if you see np in your code you can be 99.9% sure that somebody has involved numpy as np and np is actually something out of numpy so I really recommend that you do this then in your code you see
whenever there's np you know this is from numpy you know where it comes from but it's not as lengthy as numpy because sometimes the equations we are coding are already pretty long so what you need to do and that's your job again in your notebook so that you have access to numpy please import numpy
in precisely this way smp this here is wrong and now we are ready to go everybody told you that in numpy
arrays are homogeneous so they have all the same types of objects and this can be actually all
types of python objects integers, floats, complex numbers unions, even strings by default it's the python floats now this morning you very quickly heard about the numpy integers now of course if you're just using
python this is not standard to use numpy and I want to tell you something about python integers which wasn't said this morning
python integers can be arbitrary so could add another zero
at some point my computer will be blocked because it's in populations, but in principle integers in python can be arbitrarily large and the problem is if you get used to that, this is very nice but at some point
when you're going to numpy you might get bitten by the fact that the integers in numpy are really types which you haven't seen in the program before so that means that integers can be as large as 64 bits, but not large and that means
that if you're used to having arbitrarily large integers and you use numpy arrays that all of a sudden it's no longer true that integers can be arbitrarily large so the error for all of us will take a look at an example now in order to try these types out
let's take a look at how we can create numpy arrays so one thing you can use in numpy in order to look up the documentation is you can use the lookfor function in lookfor create array let's try this thing
you see you get a whole list of ways to create arrays luckily what you're really looking for is what is written here at the very top numpy.array allows us
to create an array that's really what we want to use and if we want to have more information on how to create an array, let's just ask for help this morning you saw dog strings, these are precisely these dog strings which have been mentioned this morning which we are going to use here
and here it says okay to create an array from an object an array-like object what is an array-like object? there could be a list or a list of lists you can look at that in a second
you see that there are some other variables here and you remember this one in the tutorial you learned that these are default values so you see there are some possibilities to for example, inference in the type of the variables the so-called D type the data type
and this is set to none so you can override it, you can say I want to have a float or I want to have a complex number if you don't do it then numpy will look at this value none and will do the proper action for you the default is to choose a float there are some more
possibilities here to change the behavior which are in practice not that important so what we have is a matrix a matrix, remember this list of lists here which we can now use to produce an array
so all you need to do is to say np.Array of matrix and while this still looks a bit like a list of a list, it really is an array this is now a multidimensional
array if you don't believe me just ask for the type so this this morning it's indeed a numpy any array
actually a very convenient way if you are practicing is to produce arrays in this array by means of a-range
a-range is a little bit like the range you know from 5 gives you numbers a-range of 6 from 0 to 5 and that's very convenient if you have an array where the elements are numbered in the sequence
then you know exactly what's happening so we are going to use this later on so let me create such an array that's precisely what we expect an array from 0 to 5 and now let's
look at the attributes, I've written here a function the details are really not that important, but this function will help us to learn more about the matrices, so we just defined this function and now we can ask for the attributes of the array
which we have created so we have this array with elements 0, 1, 2, 3, 4, 5 and these are the properties of this array to these properties for the dimension of the array it's a one-dimensional array the size is 6, there are 6 items
each item has the size of 8 bytes that's pretty clear because the type, the data type is 64, 64 bits for the integer the byte has 8 bits, so the item size is 8 the shape, which we will discuss later on
and all details are 6 which just means this is a tuple which tells you how many elements are there in each direction, now this is a one-dimensional array, so there's just one size and that's 6, 6 elements and the strides are 8, what are the strides?
the strides is the following, you have the array so suppose the array is here, 0, 1, 2, 3, 4, 5 and I know Python I'm playing the role of Python so I'm standing here at the beginning of the array the question is how far do I have to go in order to be at the next
element and the stride tells me how far do I have to go this is the step I have to make which is 8 because this object at the cell number 0 has the size 8 bytes and then I walk another 8 bytes and then I'm at the second element
and so on so the strides tell me how I walk through these data that's all what I need to know about this you'll see, this becomes more interesting, I don't know whether everybody could hear this, the question was what's the difference between the strides and the item size
this is a good question because in 1D this is basically the same well actually I could change the strides here for example change the strides to 16 instead of 8 what would that mean? The item sizes are still 8
but I'd help Python go instead of 16 then I go to objects you can change the step size basically and you could even play the object tricks, you can say the strides are small
and then you get the nonsense because you go in the middle of an object you just go to somewhere in the memory so this is dangerous but we are going to use this we are not going to use it that much explicitly but you can do a lot of interesting things and in the end, in the slicing
that's what's used and so there is actually a difference which becomes more important if you have multi-dimensional graphs but there are more questions at this point, we are not asking any questions so far no? yeah
you mean a matrix here in the numpy matrix? or cache and then I go to the matrix
what if you put random it gives you random variables and I think if I were to use the market rule we are going to use
random random values later on just like a race that's usually random okay okay, now so far yeah so in my case, the dtype is only
int32, so is this just belonging to the system that I am using? no no, int is fine it's only saying int I only have half of the size so for example, in my case, then the strides are for 64 so maybe this is some of the older vector
maybe then I didn't put just the wrong version it could be that your standard size is still are you using 5.3 or 5.3? 5.3 and I have a 64 bit system you may be surprised
but what would be the name if I asked you then how would you change if you really have this problem you can explicitly state with dtype that you want as you can do by standard I was just wondering because why the default size here is different yeah, I am a bit surprised because I would have expected
the price in 3 years with the 64 bit computer that you get in 64 is default if you start out from int as you did I am not completely sure what the reason is but I mean, let's play around a little bit with data types
I would like to ask you just to try out different data types like flows, complex numbers, booleans, streams what you do is you just create a list or if you want a list of lists you use an empty array to produce an array and you check its dtype you can either
you can use this array attribute which I have used here or if you want you can also say that this array my, array 1 you can just say dot dtype and see that this is in 64 so just try this out for some floats
or complex numbers booleans and streams the most interesting multiple streams use streams of different sizes like python and eurocybe and something like that
just that you see that you can create all kinds of different data types it's sufficient to have
small lists you don't need to
produce large you can see that this is prime so you can just put this here
complex numbers so you see that complex numbers
of course need twice as much memory as floats 64 times 128 because it has a real n-dimensional part and maybe most interesting
strings so in the first three cases
you see that you just get the float 64 becomes like 128 and boolean and now in the last case
in principle it doesn't look as homogeneous as we assumed an array to be because these streams have different length so what python does at this point is, well, u is a unicode character, it just looks at the longest stream which is eurocybe which contains nine characters
so every entry now has the size of nine characters even if in some cases like python we would only need six characters but every object now has the same size
let's do something interesting right before the rise here a range from 1 to 160 instead of 10 and we use it as a d-type in the a-type
just try out what this results in we understand what's going on
because the standard size of a 64-bit computer should be close to 64 the 64-bit is the standard I mean, actually, most computations there's no reason to use smaller sizes
actually in the old days when I started doing computations in science we had this all the floats so you could go up to how much was it 30 or something like that and we were looking for the double variables which
go longer 64 so actually what in scientific calculations you usually need are 64-bit so that's really the standard you shouldn't go to small numbers unless you really understand the reason because otherwise
What's happening here might happen. So what's going on here? Why do we get negative values, right? So you have one digit of sine, and only 7 was 100 itself. Yes. So you have 7 is 100, and 100 is 28.
So all numbers of that start from minus 8. Right. So we have an overflow. We are not very old about it at this point. And we just start at the other end again. So that's what I was saying here. We have overflows.
So if you think that India just invited them, it's no problem at all, because they can be arbitrarily large. Well, if you just are willing to invest 8 bytes, sorry, 8 bits here in this space, then you will overflow easily. But actually, integers in the meantime cannot be
arbitrarily large, maximum is 64. Which is more than sufficient, because after 10 to the 308, that should really be enough. But, oh, you have to be careful here. Yeah. What is data type of old?
Data is not here. I just changed it now. Yeah. What was the data type in? It's just a good question. I'll just try it now. OK.
So that just applies an object. So just so that everybody can see.
It's a pipe object. So this is actually, I mean, you could put in whatever you like. But at some point, there is no basically C-based representation anymore. So then somehow this object has to be small. But then, this is, I mean, whenever you can't do this,
I would say that your problem is using new priorities and that it's much more likely that you would lose So instead of this, I'll just try it out. I mean, basically, then you're still at 0,
because that's basically where you can represent all these elements. OK. Then you have, this would be this example, right? And the number. And the number.
OK. Let's try it out. So actually, I wouldn't have known the answer right away. But apparently, the 3.1 for 1 is converted
to a uni though. But I mean, these are really not the situations that you would want to use. Unless for specific purposes, yes. There are more questions at this point.
Then let's get a bit more into strides. I mean, the question before was, what's the point about strides if the size of the strides
is just the size of the object? Well, there's no good reason for that. But suppose you have an array instead of this one-dimensional array, 0, 1, 1, 2, 3, 4, 5. You have the 2D array, 0, 1, 2, 3, 4, 5.
Then strides are used in the following way. Tuple 24A, which means that if you are walking in this direction, you're walking in the stride of 8 from object to object. And if you are walking
downwards here, then you're walking in strides of 24. So that means that in memory, you have precisely the same thing, but we're looking at it in a different way. This is maybe one of the most important things
to note here. If you rearrange these matrix elements, if you produce a 2D array out of 1D array, also in this space here, where vertically you go in steps of 16 in this 3x2 matrix,
it's always the same thing in memory because in memory this has to be one-dimensional basically. There's nothing like 2 or 3 or 10 dimensions in memory. So you have a piece of storage where all your matrix elements are, and the difference
between these different matrices is just the way Python interprets the indices, how it accesses objects. Why is this important? The point is whenever you copy data in memory, it will cost you time.
So whenever in no time you're doing something where you're creating a new array, it will cost you time. Scientists, you don't have time because you want to run your program fast, so you want to try as much as possible. Of course, this is not possible throughout the whole program, but you want to use
the data as they are, if possible. And the strides are a way to integrate the data in a different way to have a different view on your arrays. That's an important point. So for the sake of efficiency,
Numba uses use, if possible. Of course, that to some extent depends also on you as a program. So changing one or more matrix elements in one matrix will change it all use.
So if I change here the first element, you may serve by 42, let's say, then this will be changed in all these matrices as well. Because it's always the same data we're looking at. The strides are a specialty
of 2D arrays? No, you can also have them in 10D. But then it's a tuple of 10 entries. And it also, depending in which direction you want to go, that's an element in the tuple, how far you have to go.
This is not at all 2D. 3D, let's just do an example. So if I take and rearrange I haven't explained ring shape yet.
What this does you're going to take a more detailed look at this example later. But what this does is basically produces out of the array 0 to 23 this 1D array, the 3D array with dimension 2, 3, and 4.
And now let's look at the strides.
So we now see the strides are 8, 32, and 96.
This way basically Python just takes the indices of the elements you want to access, multiplies with the respective strides and adds everything up and knows exactly the position in memory
where this element runs. Okay, one example which we are going to look at second in the examples is for example the transposition of a matrix. So if you have a matrix and you want
to look at the transpose that means you learn the matrix at its diagonal then you can understand this just as a new U on the same data. There's no need to create a new array. So let's play around with that.
So we have just to remind you how my array 1 looked like. It was this one dimensional array 0, 1, 2, 3, 4, 5 and we can do a reshape.
A reshape now does exactly what I've shown you here. It takes this array and reshapes it in a 2 by 3 matrix. 2 is basically
up down and 3 is horizontal. So these are the same data and memory but interpreted differently. So if I look at the array attributes then we see that the strides are as I've shown you before
24 and 8 and I can also use this other matrix this matrix the only difference is
that the strides are different. That's the secret of a view of how you can access or interpret data in a memory differently. Now let's see
what this implies. I've already mentioned that if now you change an element in this chunk of memory it will change in all views. So if now I say my array 1 of 0
is also one dimensional array is 42 Let's take a look at my array 1. By the way I just created a new cell. How do you create a new cell?
If you are on a cell in green you can enter something you can turn it blue so that you can't enter anything anymore you just hit escape and it becomes blue and then you can type b for button or below to create a cell
a will create a cell above and you see that of course that's no surprise. Element 0 is replaced by but what happened to my array 2?
That's the one we had reshaped of course since this is the view on the same data we have changed this as well. So reshape just produces a different
different view doesn't produce a new array. Excuse me? Does it also work the other way around? If I change array 2 does it also modify the elements? I don't. So let's correct this mistake here if you consider it as a mistake.
We have to learn yet how to access this element but let's see look at my array 2 and my array 1 this is my array 2
and my array 1 yes it is really the same data so basically you can think of that just the interface which does the calculation of where to look at elements up has changed but the data
are really the same. Now if you want to transpose something let's just create an array and transpose it so here what I do is I produce a one dimensional array from 0 to 8 I reshape
it in a 3 by 3 matrix and it's transposed. Looks like this and this is again a view on the same data. How could I copy it to a different data? There are different ways for example you could
do it very explicitly this way right now so far you don't believe me that I really have made a copy so let's change the element
b of 0 now we are in the 2 dimensional in this line let's take a look at b ok
oops, sorry that was wrong that works that works for lists it doesn't work there is a there is also a copy I thought
multiply by one sorry? multiply by one yes because the multiplication produces a new array
but that's yeah so this is probably in a better way because otherwise you still have to do computation in addition, but that's actually important so the copy works in any place but you're right
that's an important point if you do computations with matrices you multiply you always create new matrices that's not what we need to do I mean this just changes the view
but this is in fact something where people are working on it most recent views there are some most recent versions of there are some advances in this so numpy tries to analyze the operations which it's supposed to do
and tries to optimize there is actually a package called NumbaXpr which allows you to pick a string of an operation so you have A plus B times C give this as a string to NumbaXpr it will compile this for you and try to do it in an optimized way
to produce as small a number as possible of really new matrices now let me look at this at the strides
so this was our original matrix since each element has the size 8 and the strides of 8 and then since there are three elements in a row you can come to the next row by a stride of 24 and if you look at the strides
from the transpose it's just the other way around that means walking in the direction 1 is 24 so that brings me from 0 to 3 whereas walking in the other direction in the direction 0 has stride of 8 and that just means that these elements
are neural with the value n so we have this important concept of use
so here I think before the break we can talk a little bit about how to produce more interesting arrays a few interesting motifs which are used all the time A range, hit space log space 0s, 1s, di, i, rank and rank-int
at this point that's really important not this morning about the event method so you can add lists to a list elements to a list by using append append a list you can say append some element don't use
append if you can avoid there is the append method and you might think that that's also the usual way to produce arrays but whenever you add an element to an array you produce a new array
and I told you producing new arrays is expensive so if you produce an array with one million elements one element at a time this will take a long time so really avoid the things if possible you should at the beginning know how big
your arrays are going to be and then you use this personal space and you fill it with your data and you try to avoid it so that's another important aspect where any arrays differ from this
even though this morning was said that it would be better to use comprehensions anyway but often you end up doing append and here it would be terrible for your performance so let's take a look at these creation routines so A-range
that's something we have already looked at or already used it this is a generalization of the usual range it produces an array in this case starting at five going up to but it's moving 15 instead of five
so the value is not in here but it's more general it allows you to also work with loads so can you try to produce this array here
by using A-range but not for flows
there's actually one tricky point this is fine
because 1.5 is not in the list but there's actually here you can follow the track of loading errors so sometimes you might have an element in there which you don't want to have there so you could use 1.6
and then you see 1.6 is in there so that's actually a bit tricky that's a matter of rounding errors so this would work but it's not very nice actually and what I write this use much more often is linspace which works slightly differently
so linspace does the following it takes a start value, a stop value and the number of elements and you try to produce this array here with linspace
and p of linspace you choose the start, the stop the stop is included one tricky point value
so how many elements do you need? not ten eleven
you use ten then of course so one and a half eleven cause it's really the number of points
not the number of intervals number of intervals is ten number of points is eleven then there's also logspace which is used in the Q-Borg on the logarithmic scale for example from minus two to two in steps of five
so I'm going from ten to the minus two to ten to the two in steps of five equally sized intervals on the logarithmic scale that means ten to the minus two ten to the minus one ten to the one and ten to the two and you can also use other bases
or some other bases too and you get one square root of two two times square root of two and so on this is particularly useful if you are creating data in order to produce a graphic or a simulation
okay we are almost at the end of the first part maybe as an application let's briefly take a look at some graphic representation or something nice at the end of the first part
in order to do that we import from our project the pipeline module we call it as PLT that's the way everybody does it so adhere to the standards because then everybody knows what you are doing for my project there will be an extra tutorial
tomorrow we can produce the article directly here in the notebook by using this directive here but with inline and then as an example we say okay let's take array x which contains the arguments
and the linspace from circle ten in one hundred elements and let's calculate the cosine so important point what happens here I have an array of one hundred values and now if I take the cosine from NumPy I can give it an array
and it will do the calculation for all elements in this array and produce another array no need to write a loop it's very short see that NumPy can help you to write readable code you don't see that this is really an array there is no loop
much easier so let's do this and then we thought it take this nice part of the cosine now you might say oh, part of the cosine is really not that exciting so at this point I invite you to come to the second part of the tutorial
where we have some more graphics which is maybe more exciting than this cosine