BUG: Assignment of complex rank-zero arrays produces misleading error
See original GitHub issueThis all makes sense to me:
In [2]: h = zeros(5, dtype=complex)
In [3]: h[1] = 1
In [4]: h[2] = array(2)
In [5]: h[3] = 3j
In [6]: h[4] = array(4j)
In [7]: h
Out[7]: array([ 0.+0.j, 1.+0.j, 2.+0.j, 0.+3.j, 0.+4.j])
This also makes sense:
In [8]: h = zeros(5)
In [9]: h[1] = 1
In [10]: h[2] = array(2)
In [11]: h[3] = 3j
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
TypeError: can't convert complex to float
This does not make sense:
In [12]: h[4] = array(4j)
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
ValueError: setting an array element with a sequence.
The problem is not that array(4j) is a “sequence”; array(3) works fine. The problem is that it’s complex and you’re trying to put it in a real array.
Took me a long time to figure out why
scipy.signal.impulse((array([1, 1]), array([1, 1]), 15))
works but
scipy.signal.impulse((array([1, 1]), array([1, 1]), 15+0j))
does not.
Issue Analytics
- State:
- Created 10 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Bug List - Eigen
ID Product▽ Comp△ Assignee Status▽ Resolution△ Changed
1746 Eigen Core ‑ g eigen.nobody CLOS FIXE 2019‑12‑04
1571 Eigen Eigenval eigen.nobody CLOS FIXE 2019‑12‑04
1605 Eigen General...
Read more >Bug - Error displaying nested arrays in the inspector
After the transition to 2020.3.6, there was a problem with displaying nested arrays if there are more than two of them in the...
Read more >kcc/README.md at master · kparc/kcc - GitHub
The above expression looks nonsensical to a k programmer for the same reason it does to a math guy, and k will most...
Read more >Dependency tree for Bug 56456
Bug 56456 depends on 241 bugs: · 35587: -Warray-bounds does not work at all or does not find all trivial cases, and :works...
Read more >fftw3.pdf
3.2 Multi-dimensional Array Format. ... 3.2.5 Dynamic Arrays in C—The Wrong Way . ... FFTW computes the DFT of complex data, real data, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This now gives
TypeError: can't convert complex to float
in master (and probably earlier)To be honest, I don’t think I would mind changing the error type. The thing is that setting an element has a different logic, so currently the fact that it is a 0-d array is just ignored, and 0-d arrays in a way just happen to work, because they mostly behave like scalars (in fact there are some quirks for 128bit floats because of that, but there are worse quirks there and 0-d arrays are rare).