liveBook · Manning

NumPy array

As explained in Distributed Machine Learning Patterns

A NumPy array is a multidimensional, in-memory data structure provided by the NumPy library.

A NumPy array is a multidimensional, in-memory data structure common in Python’s scientific computing ecosystem. Its core properties are data, shape, and dtype. section 8.1.1

Inspect and prepare an array through its structure and values:

  • Represent MNIST training images as a 60,000 × 28 × 28 array of uint8 values ranging from 0 to 255. section 8.1.1
  • Inspect data, shape, dtype, minimum, and maximum values before modeling. section 8.1.1
  • Preprocess image features by dividing values by 255, producing values from 0.0 to 1.0 and a float64 array. section 8.1.1

Keeping a large NumPy array in memory can become a scalability problem. Feeding it to TensorFlow through tf.constant() may copy its contents multiple times; a 1.5-GB array can exceed the 2-GB tf.GraphDef protocol-buffer limit after two copies. Additional transformations can require still more memory. section 2.3.1

MNIST training pipeline

Load MNIST through tf.keras.datasets.mnist.load_data(), receive NumPy arrays for training and testing, scale the image arrays, and pass them to a Keras model for training and evaluation. section 8.1.1

Figure 2.5 An example 1.5-GB in-memory NumPy array representation that hits an out-of-memory error when being converted to a tf.GraphDef protocol buffer
02-05

Visualizes how copying a 1.5-GB in-memory NumPy array into a TensorFlow graph can produce an out-of-memory failure. section 2.3.1

How Distributed Machine Learning Patterns covers it

How deep it goes
Explains array properties, concrete dimensions, value ranges, preprocessing, and memory-copy failure modes.
Examples
Demonstrates 60,000 grayscale 28 × 28 MNIST images, array inspection, scaling by 255, and Keras training inputs.
What you can do after
Apply it via TensorFlow and Keras to load, inspect, scale, train on, and evaluate image datasets.
How it connects
Connects NumPy arrays with Python scientific computing, MNIST, feature preprocessing, TensorFlow, Keras, and tf.GraphDef.

Also explained in

Compare how 4 books explain NumPy array →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Distributed Machine Learning Patterns. The section links point to the parts of the book it draws on.