Get startedGet started for free

Reshaping tensors

Later in the course, you will classify images of sign language letters using a neural network. In some cases, the network will take 1-dimensional tensors as inputs, but your data will come in the form of images, which will either be either 2- or 3-dimensional tensors, depending on whether they are grayscale or color images.

The figure below shows grayscale and color images of the sign language letter A. The two images have been imported for you and converted to the numpy arrays gray_tensor and color_tensor. Reshape these arrays into 1-dimensional vectors using the reshape operation, which has been imported for you from tensorflow. Note that the shape of gray_tensor is 28x28 and the shape of color_tensor is 28x28x3.

This figure shows grayscale and color images of the sign language letter "A".

This exercise is part of the course

Introduction to TensorFlow in Python

View Course

Exercise instructions

  • Reshape gray_tensor from a 28x28 matrix into a 784x1 vector named gray_vector.
  • Reshape color_tensor from a 28x28x3 tensor into a 2352x1 vector named color_vector.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Reshape the grayscale image tensor into a vector
gray_vector = reshape(____, (____, 1))

# Reshape the color image tensor into a vector
color_vector = reshape(____, (____, ____))
Edit and Run Code