Add slicing access for state-space models with tests by guptavaibhav0 · Pull Request #1012 · python-control/python-control
This PR adds the capability to access state-space models using splice. This should help fix #256.
>>> b = ct.ss([[2, 3], [3, 4]], [[2, 1], [2, 3]], [[2, 4]], [[1, 2]], 0.1)
>>> b[:2, 1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../.venv/lib/python3.12/site-packages/control/statesp.py", line 1224, in __getitem__
self.A, self.B[:, inpdx], self.C[outdx, :], self.D[outdx, inpdx],
~~~~~~^^^^^^^^^^
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
>>> b = ct.ss([[2, 3], [3, 4]], [[2, 1], [2, 3]], [[2, 4]], [[1, 2]], 0.1)
>>> print(b[:2, 1])
<StateSpace>: sys[0]$indexed
Inputs (1): ['u[1]']
Outputs (1): ['y[0]']
States (2): ['x[0]', 'x[1]']
A = [[2. 3.]
[3. 4.]]
B = [[1.]
[3.]]
C = [[2. 4.]]
D = [[2.]]
dt = 0.1