✅ Put your name here

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### Goals for this pre-class assignment\n", "By the end of this assignment, you should be able to:\n", "* Review some of the basics of using NumPy arrays\n", "* Understand the motivation behind 2D NumPy arrays\n", "* Index, mask, and manipulate 2D NumPy arrays\n", "\n", "### Assignment instructions\n", "\n", "Watch the videos below, do the readings linked to below the videos, and complete the assigned programming problems. Please get started early, and come to office hours if you have any questions! Make use of Slack as well!\n", "\n", "**This assignment is due by 7:59 p.m. the day before class,** and should be uploaded into the appropriate \"Pre-class assignments\" submission folder. Submission instructions can be found at the end of the notebook." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "## Review of NumPy Arrays\n", "\n", "It's been a little while since we introduced the concept of NumPy arrays. Below are a few videos that you have seen before in the pre-class assignment that introduced NumPy arrays. If you feel like you need a review of the material or are unclear about any of the foundational concepts of using arrays, you should take the time to rewatch these videos. **If you feel like you have a good understanding of the material, feel free to skip this portion of the assignment and go right ahead to working with 2D NumPy arrays.**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import YouTubeVideo\n", "YouTubeVideo(\"BTXyE3KLIOs\",width=640,height=360)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(If the YouTube video doesn't work, try the [MediaSpace link](https://mediaspace.msu.edu/media/The+numpy+module/1_f2dka7x4))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import YouTubeVideo\n", "YouTubeVideo(\"g7epZeDA_lQ\",width=640,height=360)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(If the YouTube version doesn't work, try the [MediaSpace link](https://mediaspace.msu.edu/media/An+Introduction+to+NumPy+ArraysA+NumPy+Array+Basics/1_fz4bh3ng))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import YouTubeVideo\n", "YouTubeVideo(\"V2C9expTF1o\",width=640,height=360)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(If the YouTube video doesn't work, try the [MediaSpace link](https://mediaspace.msu.edu/media/An+Introduction+to+NumPy+ArraysA+Operations+and+Arrays/1_qu3lpypx))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "## Part 1: 2D NumPy arrays\n", "\n", "In this assignment, we are going to spend some time thinking about higher dimensional arrays. In using the term \"dimension\" when talking about arrays, it can _almost_ help to think about these like geometrical shapes or objects. A line only has a length to it, so we call it a one dimensional object. A square, however, has a length _and_ a width, so we call it a two dimensional object. Though this metaphor can start to break down as the shapes become more complex, it works for our 1D and 2D cases. A 1D array is simply a single array of value, like `array([1,2,3,4,5])`. A 2D array, which we are going to introduce here today, is as bit more complex. 2D arrays are very commonly used in computational modeling and data analysis for reasons that will hopefully be clear after today." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "✅ **To begin:** Watch this video on an introduction to 2D NumPy arrays. In this video, we will outline some real-world examples for why we might want to use these objects and go over some of the basics of creating them and using them. Answer the questions that follow after the video. (If the YouTube video doesn't work, this this [MediaSpace link](https://mediaspace.msu.edu/media/2D+NumPy+Array+Basics/1_dpq27j29))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import YouTubeVideo\n", "YouTubeVideo(\"KXPtg7iHbfw\",width=640,height=360)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "✅ **Task:** _In your own words_, explain the idea of a 2D array to a friend who has never coded before. Why do we call it a **2D** array? Can you think of an example other than the examples outlined in the videos where 2D arrays could prove to be useful? " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "✎ *Put your answer here*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### **1.1 Let's consider an example:** \n", "\n", "You may remember playing the game _Battleship_ as a kid, but if not, here is a brief overview of how the game works. Each player has a grid that they place ships onto. The other person playing makes guesses as to where their opponents ships are. If they guess correctly, the ship takes a \"hit,\" which is denoted by a red peg. If they miss, then the ship remains untouched, noted by a white peg. This continues back and forth until one player sinks all of their opponent's ships.\n", "\n", "We are going to use this game as a very basic example for making a 2D Numpy array. The grid for a game of _Battleship_ looks like the image to the right.\n", "\n", "\n", " |