archimedes.eye¶
- archimedes.eye(n: int, dtype: DTypeLike = <class 'numpy.float64'>, 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.
dtype (numpy.dtype, optional) – Data type of the array. Default is np.float64.
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