CS357 Midterm1 Review - ~25 Multple choice shorT answer...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
~25 Multiple choice, short answer, short code (possibly) The exam covers through Feb. 9th. Content • Quizes • Parts of the homework • inclass flows • slides Big ideas (incomplete list) • Types in Python • List versus an (numpy) array. Why is it faster? 0. Basics The data values for a given item form a one-dimensional array (have to be homogeneous) or list (can be heterogeneous). A one-dimensional array of numbers is called a vector . A two-dimensional array of numbers is called a matrix . 1. The Instructor's Answer As the post below indicates, the crux of the issue is memory allocation and quick access of the stored data . Lists are very flexible objects that allow storage of different types of data (i.e. different memory footprint) and allow for easy growth and contraction of the size of the object. But this comes at a cost of speed . On the other hand, consider a numpy.array. We can only store one type of data in this array. And although the appending to the array may seem as easy as to list, what has actually behind the scenes, is that every time we create a numpy.array, it actually allocates a large contiguous block of memory for that array in case we want to do np.concatenate() or a similar append-like operation. So arrays allocate memory and the storage of our values in a manner that is very systematic, which allows for quick retrieval and manipulation . 2. A Helpful Analogy Brendan Wilson 2 days ago The short answer is that arrays contain the values themselves, whereas lists contain references (i.e. pointers ) to the values. Consider the computer as your servant, and all the values you
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
might be interested in are in little boxes. Some of these boxes are very far away, so it can take some time for the computer to get them and bring the values back to you. With an array, the computer goes to the box, gets the value, and brings it back to you. But the computer is smart and knows you're impatient, so it also says "Hey, I know that when you access a value you often access the values nearby too, so I made a note of those as well. Also, I noticed that you seem to be getting these values sequentially, so I grabbed the next five hundred." Now it won't have to go all the way back to the boxes to get these values when you need them. With a list, the computer goes to get the value in the box. But when it gets there, instead of the value, it finds a note that says "Sorry, the value you want is in a different box. Here's which one." So now the computer has to go to this other box to get the value it needs. The other box could
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern