question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numpy.ndarray * control.TransferFunction gives array object

See original GitHub issue

TransferFunction doesn’t have the __array_priority = 11 class attribute that StateSpace and FrequencyResponseData do. Is this on purpose? See below for results of array * tf, which results in an array (dtype object), and array * ss, which results in a SS object. I found this while investigating the behaviour of bdalg.connect in relation with #421

Should multiplication of scalar transfer functions by arrays be special-cased so that, e.g., with scalar tf k, k * eye(5) gives a 5x5 TF with identical entries on the diagonal? I think this sort of convention is used in literature, but it might be tricky to get something consistent here (e.g., should 1-input 1-output state-space systems do something analogous?; should one do general broadcasting?)

(control-dev) rory@rory-latitude:~/src/python-control$ ipython
Python 3.8.5 | packaged by conda-forge | (default, Jul 31 2020, 02:39:48) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.17.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: !git describe                                                                                                  
0.8.3-62-g6ede92e

In [2]: import control                                                                                                 

In [3]: import numpy as np                                                                                             

In [4]: np.array([[1]]) * control.tf([1], [1,1])                                                                       
Out[4]: array([[TransferFunction(array([1.]), array([1, 1]))]], dtype=object)

In [5]: np.array([[1]]) * control.ss([[-1]], [[1]], [[1]], [[0]])                                                      
Out[5]: StateSpace(array([[-1.]]), array([[1.]]), array([[1.]]), array([[0.]]))

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
murrayrmcommented, Aug 22, 2020

My two cents:

  • As much as possible, it seems like all LTI objects should behave the same with respect to various operations. So it shouldn’t matter if you have a TransferFunction or a StateSpace system of an LTI system.

  • It also seems to me that if a control system object (LTI or InputOutputSystem) is in an expression where you would expect to get back a control system object, things should work as expected. This basically prioritizes the control objects over numpy objects (I think).

For the specific case above, I would have expected to get a TransferFunction back. I’d be interested to hear what others things about this.

0reactions
murrayrmcommented, Sep 12, 2020

LinearIOSystem and InterconnectedSystems are both subclasses of InputOutputSystem. Any operation with an LTI system that can be converted to a StateSpace system can (and probably should) be promoted to an InputOutput system. Note that you can’t combine an FRD system with an InputOutputSystem since the former is has (only) a frequency domain representation and later has (only) a state space representation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

control.TransferFunction - Python Control Systems Library
The TransferFunction class is used to represent systems in transfer function form. ... list or a numpy array and will be sorted before...
Read more >
numpy.ndarray — NumPy v1.24 Manual
Returns a field of the given array as a certain type. item (*args). Copy an element of an array to a standard Python...
Read more >
Array objects — NumPy v1.24 Manual
NumPy provides an N-dimensional array type, the ndarray, which describes a collection of “items” of the same type. The items can be indexed...
Read more >
Array manipulation routines — NumPy v1.24 Manual
Gives a new shape to an array without changing its data. ravel (a[, order]). Return a contiguous flattened array. ndarray.flat.
Read more >
Python Control Documentation
Returns poles: ndarray : Array that contains the system's poles. Raises NotImplementedError : when called on a TransferFunction object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found