Defining data as constants
Throughout this course, we will use tensorflow version 2.6.0 and will exclusively import the submodules needed to complete each exercise. This will usually be done for you, but you will do it in this exercise by importing constant from tensorflow.
After you have imported constant, you will use it to transform a numpy array, credit_numpy, into a tensorflow constant, credit_constant. This array contains feature columns from a dataset on credit card holders and is previewed in the image below. We will return to this dataset in later chapters.
Note that tensorflow 2 allows you to use data as either a numpy array or a tensorflow constant object. Using a constant will ensure that any operations performed with that object are done in tensorflow.

Questo esercizio fa parte del corso
Introduction to TensorFlow in Python
Istruzioni dell'esercizio
- Import the
constantsubmodule from thetensorflowmodule. - Convert the
credit_numpyarray into aconstantobject intensorflow. Do not set the data type.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Import constant from TensorFlow
from tensorflow import ____
# Convert the credit_numpy array into a tensorflow constant
credit_constant = constant(____)
# Print constant datatype
print('\n The datatype is:', credit_constant.dtype)
# Print constant shape
print('\n The shape is:', credit_constant.shape)