Tensors – multidimensional arrays

Now that we've learned a bit about MNIST digits, we're going to take the time to look at a tensor, and what a tensor is. We're going to be looking at a NumPy of multidimensional arrays. Multidimensional arrays are also called tensors. The math vocabulary can be mildly overwhelming, but we're going to show you that it's a lot simpler than you might think. Then, we'll look at tensor shape. Tensor shape is really the number of dimensions, or, in terms of arrays, the number of different indices that you would use to access them. And then finally, we're going to look at datatypes. The tensors, or multidimensional arrays, can hold a wide array of different datatypes, and we'll explain some of the differences.

Let's start with the basics. The most basic tensor you can imagine is a one tensor, which, in programming language is just called an array. It is just an ordered series of individual numbers packed together. Next up is a two tensor. If you look at the Grey scale image (arrays of array) screenshot, each row is of one dimension, and each column is another dimension.

So, row by row, this adds up to being a two tensor. Again, it's just an array of arrays. And you can see that there are trained images with the bracket zero; we're actually picking out the first image in an array of images. So, a three tensor, preceding with image data, is actually an array of images, each with an array of columns and rows of pixels. So, a three tensor is our basic way of storing black and white images.

As a quick visualization, as you can see in the image at index one, the Xs and the Ys (the coordinates that are shown following on the digit) are simply the dimensions of the tensor:

Dimension of the tensor

Now, let's talk about shape. You can see here that we call .shape on the NumPy multidimensional array, or tensor, and it comes back with 60000, 28, 28:

Calling .shape 

These are the three dimensions that make up our three tensors. And it's just a multidimensional array. Then, there's of course the datatype, or the dtype, as you call it here on the NumPy multidimensional array. You can see that these images are stored as uint8, or 8-bit integers, to record the 0 to 255 values. Well, we'll often use this datatype for source data, particularly for black and white images like the preceding one. When we convert it into the actual machine learning format, we're going to be working with floating point.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.254.44