Title: Numpy automatically casting Complex to Float · Issue #551 · python-control/python-control · GitHub
Open Graph Title: Numpy automatically casting Complex to Float · Issue #551 · python-control/python-control
X Title: Numpy automatically casting Complex to Float · Issue #551 · python-control/python-control
Description: It's been a while since i've used this awesome work you guys did. Tried some simple things today and couldn't get it to work I believe numpy got updated and messed some things up Given the following code: import control as ct import nump...
Open Graph Description: It's been a while since i've used this awesome work you guys did. Tried some simple things today and couldn't get it to work I believe numpy got updated and messed some things up Given the followin...
X Description: It's been a while since i've used this awesome work you guys did. Tried some simple things today and couldn't get it to work I believe numpy got updated and messed some things up Given ...
Opengraph URL: https://github.com/python-control/python-control/issues/551
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Numpy automatically casting Complex to Float","articleBody":"It's been a while since i've used this awesome work you guys did.\r\nTried some simple things today and couldn't get it to work\r\n\r\nI believe numpy got updated and messed some things up\r\n\r\nGiven the following code:\r\n```\r\nimport control as ct\r\nimport numpy as np\r\n\r\n# Define Poles and get it's coeficients\r\npoles = np.array([np.complex(-7.7, 6.4), np.complex(7.7, 6.4)]) # Expecting to get these poles when G.pole() is called\r\ncoefs = np.poly(poles)\r\n\r\n# Define the Transfer Function\r\nnum = [1]\r\nden = coefs\r\nG = ct.tf(num, den)\r\n\r\n# Get the poles\r\nG.pole()\r\n```\r\n\r\ni get these warnings:\r\n\r\n`\r\n/usr/local/lib/python3.7/dist-packages/control/xferfcn.py:957: ComplexWarning: Casting complex values to real discards the imaginary part den[j, :maxindex+1] = poly(poles[j])\r\n`\r\n`\r\n/usr/local/lib/python3.7/dist-packages/control/xferfcn.py:987: ComplexWarning: Casting complex values to real discards the imaginary part num[i, j, maxindex+1-len(numpoly):maxindex+1] = numpoly\r\narray([-10.0124922, 10.0124922])\r\n`\r\n\r\nDoing a few tests i found out that\r\n\r\n```\r\npoles = np.array([np.complex(-7.7, 6.4), np.complex(7.7, 6.4)])\r\n\r\nmaxindex = 2\r\nden = np.zeros((1, maxindex + 1), dtype=np.float)\r\nden[0, :maxindex + 1] = np.poly(poles)\r\n```\r\n`/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:5: ComplexWarning: Casting complex values to real discards the imaginary part`\r\nwill results in the same warnings, but changing dtype to np.complex it works correctly\r\n```\r\npoles = np.array([np.complex(-7.7, 6.4), np.complex(7.7, 6.4)])\r\n\r\nmaxindex = 2\r\nden = np.zeros((1, maxindex + 1), dtype=np.complex)\r\nden[0, :maxindex + 1] = np.poly(poles)\r\nden\r\n```\r\n`array([ 1. +0.j , 0. -12.8j, -100.25 +0.j ])`\r\n\r\nI belive changing the num and den dtype to np.complex from xferfcn.py file should solve the issue (did not look up for similar issues/solutions though)\r\n```\r\n938 den = zeros((self.inputs, maxindex + 1), dtype=np.complex)\r\n939 num = zeros((max(1, self.outputs, self.inputs),\r\n940 max(1, self.outputs, self.inputs),\r\n941 maxindex + 1),\r\n942 dtype=np.complex)\r\n```\r\n","author":{"url":"https://github.com/Bruno-SW","@type":"Person","name":"Bruno-SW"},"datePublished":"2021-02-24T19:30:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/551/python-control/issues/551"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d60637c1-aa29-b280-e41b-70efd4353712 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8264:273E4:5FD993:873D76:6979ED8B |
| html-safe-nonce | 8b39b00279c8510356b18328792b36f4a6049bb57b678e34891092395f336b94 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjY0OjI3M0U0OjVGRDk5Mzo4NzNENzY6Njk3OUVEOEIiLCJ2aXNpdG9yX2lkIjoiNDkyMDcxNTI3MjQ0MjMwMDI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7ec01c512e16fc7e6d93adea467df034182db3b27034117d298867caa80caa47 |
| hovercard-subject-tag | issue:815777719 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-control/python-control/551/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e59a903bcfc450a897bddd299ffe39ec78a2d87868ef3b5cc979a24bb7d1515b/python-control/python-control/issues/551 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e59a903bcfc450a897bddd299ffe39ec78a2d87868ef3b5cc979a24bb7d1515b/python-control/python-control/issues/551 |
| og:image:alt | It's been a while since i've used this awesome work you guys did. Tried some simple things today and couldn't get it to work I believe numpy got updated and messed some things up Given the followin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Bruno-SW |
| hostname | github.com |
| expected-hostname | github.com |
| None | d518616844426fb176f4177c4776349f6e70ef1ce75f459c8c53bf9293bb6982 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-control/python-control git https://github.com/python-control/python-control.git |
| octolytics-dimension-user_id | 2285872 |
| octolytics-dimension-user_login | python-control |
| octolytics-dimension-repository_id | 22791752 |
| octolytics-dimension-repository_nwo | python-control/python-control |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 22791752 |
| octolytics-dimension-repository_network_root_nwo | python-control/python-control |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 22c6ce7724007ae85d7487fce3308a1c7cea8be6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width