Get startedGet started for free

Working with image data

You are given a black-and-white image of a letter, which has been encoded as a tensor, letter. You want to determine whether the letter is an X or a K. You don't have a trained neural network, but you do have a simple model, model, which can be used to classify letter.

The 3x3 tensor, letter, and the 1x3 tensor, model, are available in the Python shell. You can determine whether letter is a K by multiplying letter by model, summing over the result, and then checking if it is equal to 1. As with more complicated models, such as neural networks, model is a collection of weights, arranged in a tensor.

Note that the functions reshape(), matmul(), and reduce_sum() have been imported from tensorflow and are available for use.

This exercise is part of the course

Introduction to TensorFlow in Python

View Course

Exercise instructions

  • The model, model, is 1x3 tensor, but should be a 3x1. Reshape model.
  • Perform a matrix multiplication of the 3x3 tensor, letter, by the 3x1 tensor, model.
  • Sum over the resulting tensor, output, and assign this value to prediction.
  • Print prediction using the .numpy() method to determine whether letter is K.

Hands-on interactive exercise

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

# Reshape model from a 1x3 to a 3x1 tensor
model = ____(model, (____, ____))

# Multiply letter by model
output = ____(letter, model)

# Sum over output and print prediction using the numpy method
prediction = ____
print(prediction.____)
Edit and Run Code