Tensor Properties
import tensorflow as tf # Create tensors tensor_1D = tf.constant([1, 2, 3]) tensor_2D = tf.constant([ [1, 2], [3, 4] ]) tensor_3D = tf.constant([ [[1, 2], [3, 4]], [[5, 6], [7, 8]] ]) # Get ranks print(f'Rank of 1D tensor: {tensor_1D.ndim}') print(f'Rank of 2D tensor: {tensor_2D.ndim}') print(f'Rank of 3D tensor: {tensor_3D.ndim}')
import tensorflow as tf # Create tensors tensor_1D = tf.constant([1, 2, 3, 4]) tensor_2D = tf.constant([ [1, 2, 3], [4, 5, 6] ]) tensor_3D = tf.constant([ [[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]], [[13, 14, 15], [16, 17, 18]] ]) # Get shapes print(f'Shape of 1D tensor: {tensor_1D.shape}') print(f'Shape of 2D tensor: {tensor_2D.shape}') print(f'Shape of 3D tensor: {tensor_3D.shape}')
import tensorflow as tf # Create tensors tensor_int = tf.constant([1, 2, 3, 4]) tensor_float = tf.constant([1., 2., 3., 4.]) tensor_string = tf.constant(['a', 'b', 'c', 'd']) # Get data type print(f'Data type of 1D tensor: {tensor_int.dtype}') print(f'Data type of 2D tensor: {tensor_float.dtype}') print(f'Data type of 3D tensor: {tensor_string.dtype}')
Завдання
Swipe to start coding
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!