sfstoolbox/sfs-python

Error with NumPy 1.11.0: ValueError: Setting an array element with a sequence

hagenw opened this issue · 6 comments

To produce this error, please run the following:

import numpy as np
import matplotlib.pyplot as plt
import sfs
xs = 0, 0, 0
omega = 2 * np.pi * 800
grid = sfs.util.xyz_grid([-1.75, 1.75], [-1.75, 1.75], 0, spacing=0.02)
p = sfs.mono.source.point(omega, xs, [], grid)

This results in

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sfs/mono/source.py", line 67, in point
    r = np.linalg.norm(grid - x0)
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 2116, in norm
    x = x.astype(float)
ValueError: setting an array element with a sequence.

The code above comes from the Python examples in the SFS documentation, which was running fine 2 month ago.

This seems to be a regression in NumPy, see numpy/numpy#7575.

That means the best workaround is to downgrade numpy?
Or is there another possibility by for example using another syntax for the definition of source position?

Either downgrade or patch: mgeier/numpy@90c8cc2

I wouldn't know a way to work around this on our side.
Being able to do math operations on object arrays is on the very base of the design of this library. It's used everywhere. Not having this feature would make our code much more ugly and verbose.

I've submitted a PR to NumPy: numpy/numpy#7587.
Let's hope that this will be fixed in version 1.11.1!

In the meantime, my fix can be applied for 1.11.0 directly in the file numpy/linalg/linalg.py. After re-starting the Python interpreter, this should work fine.

As a work-around, it was suggested to define our own norm() function:

def norm(x):
    return np.sqrt(np.dot(x, x))

That was fixed in 1.11.1 and we solved it by exclude this numpy version:

'numpy!=1.11.0'