From the course: Python Data Analysis

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Creating NumPy arrays

Creating NumPy arrays - Python Tutorial

From the course: Python Data Analysis

Creating NumPy arrays

- [Instructor] Let's get started with NumPy arrays. The easiest way to get one is to load it from a file. NumPy recognizes several file formats. These include, of course, simple text files. I have prepared one for you that describes a very well known lady. The file is called monalisa.txt. Let's have a look at its contents. So we see that each line is a sequence of integers and we have 200 lines all together. NumPy will load this file without any trouble. The result is a two-dimensional array. When we display it, NumPy omits some rows and columns so it fits on the screen. We can query this object for the number of dimensions. Two, since it's an array. For the shape, 200 by 134. For the total number of elements and the number of bytes in memory. And for the type of the array elements. An eight byte floating point number. Okay, so clearly this is an image and we can use the matplotlib function imshow to display a two dimensional and NumPy array as an image. Although we should probably…

Contents