archimedes.ones¶
- archimedes.ones(shape: ShapeLike, dtype: DTypeLike = <class 'numpy.float64'>, kind: str = 'MX') SymbolicArray ¶
Construct a symbolic array of ones with the given shape and dtype.
This function creates an array filled with the value 1, equivalent to NumPy’s ones function but returning a symbolic array suitable for use in symbolic computations.
- Parameters:
shape (int or tuple of ints) – Shape of the array. A single integer n creates a vector of length n. A tuple (m, n) creates an m×n 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 for element-wise operations.
MX: Matrix-based symbolic type. The entire array is represented by a single symbolic object. Supports a broader range of operations.
- Returns:
Symbolic array of ones with the given shape, dtype, and symbolic kind.
- Return type:
SymbolicArray
Notes
This function is the symbolic counterpart to NumPy’s ones function. It’s useful for initializing arrays with ones in symbolic computation contexts, such as creating weight matrices, mask arrays, or default values for symbolic computation.
When working within a function that will be executed with both symbolic and numeric arrays, prefer using
np.ones_like
ornp.ones(..., like=x)
wherex
is either a SymbolicArray or NumPy array. This provides better compatibility across both numeric and symbolic execution paths.Examples
>>> import archimedes as arc >>> import numpy as np >>> >>> # Create a vector of ones >>> o1 = arc.ones(5) >>> print(o1) [1, 1, 1, 1, 1] >>> >>> # Create a matrix of ones >>> o2 = arc.ones((2, 3)) >>> print(o2) [[1, 1, 1], [1, 1, 1]] >>> >>> # Create MX-type ones >>> o3 = arc.ones(4, kind="MX")
See also
numpy.ones
NumPy’s array of ones function
ones_like
Create an array of ones with shape/dtype of an input array
zeros
Create an array of zeros
eye
Create an identity matrix
array
Create an array from data