官术网_书友最值得收藏!

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 objects
import numpy as np
import tensorflow as tf

# create a 2x2 matrix in various forms
matrix1 = [[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, dtype=tf.float32)
tensorForM3 = tf.convert_to_tensor(matrix3, dtype=tf.float32)

print(type(tensorForM1))
print(type(tensorForM2))
print(type(tensorForM3))

The output of the listing is shown in the following code:

<class 'list'>
<class 'numpy.ndarray'>
<class 'tensorflow.python.framework.ops.Tensor'>
<class 'tensorflow.python.framework.ops.Tensor'>
<class 'tensorflow.python.framework.ops.Tensor'>
<class 'tensorflow.python.framework.ops.Tensor'>
主站蜘蛛池模板: 开平市| 岑溪市| 河南省| 时尚| 遂川县| 栾川县| 双城市| 磴口县| 深州市| 五台县| 浮山县| 芒康县| 年辖:市辖区| 五峰| 那坡县| 杭锦旗| 儋州市| 霍州市| 尤溪县| 大方县| 呼伦贝尔市| 清河县| 丰宁| 辉县市| 图片| 苏尼特左旗| 阳山县| 滦南县| 永和县| 巨鹿县| 长海县| 梅河口市| 荣成市| 桑植县| 陆河县| 开远市| 麟游县| 宜章县| 沂南县| 建阳市| 东阳市|