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

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'>
主站蜘蛛池模板: 若尔盖县| 沈阳市| 双城市| 皮山县| 鄢陵县| 博野县| 安仁县| 水富县| 内丘县| 土默特左旗| 三穗县| 河曲县| 安达市| 静乐县| 保德县| 都安| 永济市| 吴江市| 时尚| 德保县| 屯昌县| 林州市| 江都市| 温泉县| 纳雍县| 博罗县| 宝应县| 宁晋县| 鄢陵县| 大埔区| 都匀市| 兴安盟| 师宗县| 青神县| 利辛县| 尉犁县| 东平县| 高陵县| 竹山县| 日土县| 锡林郭勒盟|