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.

BUG: Assignment of complex rank-zero arrays produces misleading error

See original GitHub issue

This 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:closed
  • Created 10 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, Jul 23, 2018

This now gives TypeError: can't convert complex to float in master (and probably earlier)

0reactions
sebergcommented, Dec 13, 2013

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).

Read more comments on GitHub >

github_iconTop 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 >

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