Skip to content

Convert TransferFunction's shallow copy to deep copy. #130

@dapperfu

Description

@dapperfu

I spent quite a bit of time trying to debug an error and finally stumbled on the documentation:

# Beware: this is a shallow copy! This should be okay,
# but be careful.

It took me a bit of digging and debugging before I realized my errors caused by the shallow copy:

>>> print(num)
>>> print(type(num[0]))

[[1], [2]]
<class 'list'>

>>> sys1 = control.TransferFunction([num],[den])
>>> sys1

>>> print(num)
>>> print(type(num[0]))

[array([1]), array([2])]
<class 'numpy.ndarray'>

This can make scripts behave different based on the order of operation:

num = ...
den = ...
myfunc(num)
TransferFunction(num, den)

vs.

num = ...
den = ...
TransferFunction(num, den)
myfunc(num)

To new Python users having the variables 'num' & 'den' behave different before and after calling TransferFunction can be confusing and off-putting.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy