CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-tensorflow

An end-to-end open source platform for machine learning

Pending
Overview
Eval results
Files

core.mddocs/

Core Tensor Operations

Fundamental tensor creation, manipulation, and mathematical operations that form the foundation of TensorFlow computations. These operations provide the building blocks for constructing complex machine learning models and numerical computations.

Capabilities

Tensor Creation

Create tensors from various data sources including constants, variables, and Python data structures.

def constant(value, dtype=None, shape=None, name="Const"):
    """
    Creates a constant tensor from tensor-like objects.
    
    Parameters:
    - value: A constant value (or list) of output type dtype or a list of values of type dtype
    - dtype: The type of the elements of the resulting tensor
    - shape: Optional dimensions of resulting tensor
    - name: Optional name for the operation
    
    Returns:
    A Constant Tensor
    """

def Variable(initial_value, trainable=None, validate_shape=True, 
             caching_device=None, name=None, variable_def=None, dtype=None, 
             import_scope=None, constraint=None, synchronization=tf.VariableSynchronization.AUTO, 
             aggregation=tf.VariableAggregation.NONE, shape=None, 
             experimental_enable_variable_lifting=True):
    """
    Creates a new variable with value initial_value.
    
    Parameters:
    - initial_value: A Tensor, or Python object convertible to a Tensor
    - trainable: If True, GradientTapes automatically watch uses of this Variable
    - validate_shape: If False, allows the variable to be initialized with a value of unknown shape
    - caching_device: Optional device string describing where the Variable should be cached
    - name: Optional name for the variable
    - dtype: If set, initial_value will be converted to the given type
    - constraint: An optional projection function to be applied to the variable after being updated
    - synchronization: Indicates when a distributed a variable will be aggregated
    - aggregation: Indicates how a distributed variable will be aggregated
    - shape: The shape of this variable
    - experimental_enable_variable_lifting: Whether to enable variable lifting optimization
    
    Returns:
    A Variable
    """

def zeros(shape, dtype=tf.float32, name=None):
    """
    Creates a tensor with all elements set to zero.
    
    Parameters:
    - shape: A list of integers, a tuple of integers, or a 1-D Tensor of type int32
    - dtype: The type of an element in the resulting Tensor
    - name: A name for the operation
    
    Returns:
    A Tensor with all elements set to zero
    """

def ones(shape, dtype=tf.float32, name=None):
    """
    Creates a tensor with all elements set to one.
    
    Parameters:
    - shape: A list of integers, a tuple of integers, or a 1-D Tensor of type int32
    - dtype: The type of an element in the resulting Tensor
    - name: A name for the operation
    
    Returns:
    A Tensor with all elements set to one
    """

def fill(dims, value, name=None):
    """
    Creates a tensor filled with a scalar value.
    
    Parameters:
    - dims: A Tensor of type int32. 1-D. Represents the shape of the output tensor
    - value: A Tensor. 0-D (scalar). Value to fill the returned tensor
    - name: A name for the operation
    
    Returns:
    A Tensor
    """

def reshape(tensor, shape, name=None):
    """
    Reshapes a tensor.
    
    Parameters:
    - tensor: A Tensor
    - shape: A Tensor of type int32. Defines the shape of the output tensor
    - name: A name for the operation
    
    Returns:
    A Tensor. Has the same type as tensor
    """

def transpose(a, perm=None, conjugate=False, name="transpose"):
    """
    Transposes a tensor.
    
    Parameters:
    - a: A Tensor
    - perm: A permutation of the dimensions of a
    - conjugate: Setting it to True is mathematically equivalent to tf.math.conj(tf.transpose(input))
    - name: A name for the operation
    
    Returns:
    A transposed Tensor
    """

def eye(num_rows, num_columns=None, batch_shape=None, dtype=tf.float32, name=None):
    """
    Construct an identity matrix, or a batch of matrices.
    
    Parameters:
    - num_rows: Non-negative int32 scalar Tensor giving the number of rows in each batch matrix
    - num_columns: Optional non-negative int32 scalar Tensor giving the number of columns
    - batch_shape: A list or tuple of Python integers or a 1-D int32 Tensor
    - dtype: The type of an element in the resulting Tensor
    - name: A name for this Op
    
    Returns:
    A Tensor of shape batch_shape + [num_rows, num_columns]
    """

Type Conversion and Casting

Convert tensors between different data types and formats.

def convert_to_tensor(value, dtype=None, dtype_hint=None, name=None):
    """
    Converts the given value to a Tensor.
    
    Parameters:
    - value: An object whose type has a registered Tensor conversion function
    - dtype: Optional element type for the returned tensor
    - dtype_hint: Optional element type for the returned tensor, used when dtype is None
    - name: Optional name to use if a new Tensor is created
    
    Returns:
    A Tensor based on value
    """

def cast(x, dtype, name=None):
    """
    Casts a tensor to a new type.
    
    Parameters:
    - x: A Tensor or SparseTensor or IndexedSlices of numeric type
    - dtype: The destination type
    - name: A name for the operation
    
    Returns:
    A Tensor or SparseTensor or IndexedSlices with same shape as x and requested dtype
    """

def to_float(x, name="ToFloat"):
    """
    Casts a tensor to type float32.
    
    Parameters:
    - x: A Tensor or SparseTensor or IndexedSlices
    - name: A name for the operation
    
    Returns:
    A Tensor or SparseTensor or IndexedSlices with same shape as x with type float32
    """

def to_double(x, name="ToDouble"):
    """
    Casts a tensor to type float64.
    
    Parameters:
    - x: A Tensor or SparseTensor or IndexedSlices
    - name: A name for the operation
    
    Returns:
    A Tensor or SparseTensor or IndexedSlices with same shape as x with type float64
    """

def to_int32(x, name="ToInt32"):
    """
    Casts a tensor to type int32.
    
    Parameters:
    - x: A Tensor or SparseTensor or IndexedSlices
    - name: A name for the operation
    
    Returns:
    A Tensor or SparseTensor or IndexedSlices with same shape as x with type int32
    """

def to_int64(x, name="ToInt64"):
    """
    Casts a tensor to type int64.
    
    Parameters:
    - x: A Tensor or SparseTensor or IndexedSlices
    - name: A name for the operation
    
    Returns:
    A Tensor or SparseTensor or IndexedSlices with same shape as x with type int64
    """

Shape Manipulation

Operations for inspecting and manipulating tensor shapes and dimensions.

def shape(input, name=None, out_type=tf.int32):
    """
    Returns the shape of a tensor.
    
    Parameters:
    - input: A Tensor or SparseTensor
    - name: A name for the operation
    - out_type: The desired output type
    
    Returns:
    A Tensor of type out_type
    """

def size(input, name=None, out_type=tf.int32):
    """
    Returns the size of a tensor.
    
    Parameters:
    - input: A Tensor or SparseTensor
    - name: A name for the operation
    - out_type: The desired output type
    
    Returns:
    A Tensor of type out_type
    """

def rank(input, name=None):
    """
    Returns the rank of a tensor.
    
    Parameters:
    - input: A Tensor or SparseTensor
    - name: A name for the operation
    
    Returns:
    A Tensor of type int32
    """

def reshape(tensor, shape, name=None):
    """
    Reshapes a tensor.
    
    Parameters:
    - tensor: A Tensor
    - shape: A Tensor of type int32. Defines the shape of the output tensor
    - name: A name for the operation
    
    Returns:
    A Tensor. Has the same type as tensor
    """

def squeeze(input, axis=None, name=None):
    """
    Removes dimensions of size 1 from the shape of a tensor.
    
    Parameters:
    - input: A Tensor. The input to squeeze
    - axis: An optional list of ints. If specified, only squeezes the dimensions listed
    - name: A name for the operation
    
    Returns:
    A Tensor. Has the same type as input
    """

def expand_dims(input, axis, name=None):
    """
    Inserts a dimension of 1 into a tensor's shape.
    
    Parameters:
    - input: A Tensor
    - axis: 0-D (scalar). Specifies the dimension index at which to expand
    - name: A name for the operation
    
    Returns:
    A Tensor with the same data as input, but its shape has an additional dimension of size 1
    """

Tensor Utilities

Utility functions for tensor inspection and manipulation.

def identity(input, name=None):
    """
    Return a tensor with the same shape and contents as input.
    
    Parameters:
    - input: A Tensor
    - name: A name for this operation
    
    Returns:
    A Tensor. Has the same type as input
    """

def stop_gradient(input, name=None):
    """
    Stops gradient computation.
    
    Parameters:
    - input: A Tensor or IndexedSlices
    - name: A name for the operation
    
    Returns:
    A Tensor or IndexedSlices. Has the same type as input
    """

def is_tensor(x):
    """
    Checks whether x is a tensor or "tensor-like".
    
    Parameters:
    - x: A python object to check
    
    Returns:
    True if x is a tensor or "tensor-like", False if not
    """

def name_scope(name, default_name=None, values=None):
    """
    A context manager for use when defining a Python op.
    
    Parameters:
    - name: The name argument that is passed to the op function
    - default_name: The default name to use if the name argument is None
    - values: The list of Tensor arguments that are passed to the op function
    
    Returns:
    A context manager that yields the current name scope
    """

Usage Examples

import tensorflow as tf

# Create tensors
x = tf.constant([1, 2, 3, 4])
y = tf.Variable([1.0, 2.0, 3.0, 4.0])
z = tf.zeros((2, 3))
identity_matrix = tf.eye(4)

# Type conversion
x_float = tf.cast(x, tf.float32)
x_tensor = tf.convert_to_tensor([1, 2, 3])

# Shape manipulation
print(tf.shape(x))  # [4]
print(tf.size(x))   # 4
print(tf.rank(x))   # 1

# Reshape operations
reshaped = tf.reshape(x, (2, 2))
expanded = tf.expand_dims(x, axis=0)  # Shape: (1, 4)
squeezed = tf.squeeze(expanded)       # Shape: (4,)

# Utilities
identity_x = tf.identity(x)
no_grad_x = tf.stop_gradient(x)

Install with Tessl CLI

npx tessl i tessl/pypi-tensorflow

docs

core.md

data.md

distribute.md

image.md

index.md

keras.md

math.md

nn.md

saved-model.md

tile.json