Python class
Weight
Weight
class max.graph.Weight(*args, **kwargs)
Bases: TensorValue
Represents a value in a Graph that can be loaded at a later time.
Weights can be initialized outside of a Graph and are lazily-added to the parent graph when used. If there is no parent graph when a weight is used, an error will be raised.
align
dtype
property dtype*: DType*
Returns the tensor data type.
matrix = np.array([[1, 2], [3, 4]], dtype=np.float32)
with Graph("dtype_demo") as graph:
# Create a constant tensor from the matrix
tensor = ops.constant(matrix, dtype=DType.float32)
print(f"Data type: {tensor.dtype}") # Output: Data type: DType.float32
matrix = np.array([[1, 2], [3, 4]], dtype=np.float32)
with Graph("dtype_demo") as graph:
# Create a constant tensor from the matrix
tensor = ops.constant(matrix, dtype=DType.float32)
print(f"Data type: {tensor.dtype}") # Output: Data type: DType.float32
quantization_encoding
quantization_encoding*: QuantizationEncoding | None*
shape
property shape*: Shape*
Returns the shape of the TensorValue
.
matrix = np.array([[1, 2], [3, 4]], dtype=np.float32)
# Create a Graph context to work with tensors
with Graph("shape_demo") as graph:
# Create a constant tensor from the matrix
tensor = ops.constant(matrix, dtype=DType.float32)
# Access tensor properties
print(f"Shape: {tensor.shape}") # Output: Shape: (2, 2)
matrix = np.array([[1, 2], [3, 4]], dtype=np.float32)
# Create a Graph context to work with tensors
with Graph("shape_demo") as graph:
# Create a constant tensor from the matrix
tensor = ops.constant(matrix, dtype=DType.float32)
# Access tensor properties
print(f"Shape: {tensor.shape}") # Output: Shape: (2, 2)
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!