Matrices

A matrix is a two-dimensional array of numbers where each element is identified by two indices instead of just one. If a real matrix X has a height of m and a width of n, then we say that X ∈ Rm × n. Here, R is a set of real numbers.

The following example shows how different matrices are converted to tensor objects:

# convert matrices to tensor objectsimport numpy as npimport tensorflow as tf# create a 2x2 matrix in various formsmatrix1 = [[1.0, 2.0], [3.0, 40]]matrix2 = np.array([[1.0, 2.0], [3.0, 40]], dtype=np.float32)matrix3 = tf.constant([[1.0, 2.0], [3.0, 40]])print(type(matrix1))print(type(matrix2))print(type(matrix3))tensorForM1 = tf.convert_to_tensor(matrix1, dtype=tf.float32)tensorForM2 = tf.convert_to_tensor(matrix2,  ...

Get Neural Network Programming with TensorFlow now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.