archimedes.eye¶
- archimedes.eye(N: int, M: int | None = None, k: int = 0, dtype: DTypeLike = <class 'numpy.float64'>, order: str = 'C', device: str = 'cpu', kind: str = 'MX') SymbolicArray ¶
Construct a symbolic identity matrix of size n with the given dtype.
This function creates an n×n matrix with ones on the diagonal and zeros elsewhere, equivalent to NumPy’s eye function but returning a symbolic array suitable for use in symbolic computations.
- Parameters:
N (int) – Size of the identity matrix.
M (int, optional) – Number of columns in the identity matrix. If None (default), M is set to N, creating a square matrix.
k (int, optional) – Index of the diagonal. If None (default), the main diagonal is used.
dtype (numpy.dtype, optional) – Data type of the array. Default is np.float64.
order ({"C", "F"}, optional) – Memory layout order of the array. For compatibility with NumPy only - ignored by this implementation.
device (str, optional) – Device to create the array on. For compatibility with NumPy only - ignored by this implementation.
kind ({"SX", "MX"}, optional) –
Kind of symbolic variable to create. Default is “MX”.
SX: Scalar-based symbolic type. Each element has its own symbolic representation. Generally more efficient.
MX: Matrix-based symbolic type. The entire array is represented by a single symbolic object. Supports a broader range of operations.
- Returns:
Identity matrix of shape (n, n) with the given dtype and symbolic kind.
- Return type:
SymbolicArray
Notes
The identity matrix is a square matrix with ones on the main diagonal and zeros elsewhere.
When working within a function that will be executed with both symbolic and numeric arrays, prefer using np.eye(…, like=x) where x is either a SymbolicArray or NumPy array, for better compatibility with numerical inputs. This function will automatically be dispatched to by NumPy when x is symbolic.
Examples
>>> import archimedes as arc >>> import numpy as np >>> >>> # Create a 3×3 identity matrix >>> I = arc.eye(3, kind="SX") >>> print(I) [[1, 0, 0], [0, 1, 0], [0, 0, 1]] >>> >>> # Create an MX-type identity matrix (default) >>> I_mx = arc.eye(4) >>> >>> # Use in matrix operations >>> x = arc.sym("x", shape=(3, 3)) >>> identity_transform = I @ x # Equivalent to x