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.

ValueError with numpy 1.16

See original GitHub issue

Hi,

Our PRE release bots, which using Numpy 1.16, failed many times with this error: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() (see https://github.com/nipy/dipy/issues/1579)

Here a small example to reproduce our problem:

simple_mp.pyx file:

import numpy as np
import cython

def masking_test():
	simple_wm = np.array([[0, 0, 0, 0, 0, 0],
                          [0, 0, 1, 0, 0, 0],
                          [0, 1, 1, 1, 0, 0],
                          [0, 1, 1, 1, 0, 0],
                          [0, 0, 0, 0, 0, 0]])
	mask = np.zeros(simple_wm.shape)

	simple_wm[mask==0] = 1

Test in a Python terminal after compiling:

>>> import simple_mp as m
>>> m.masking_test()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "simple_mp.pyx", line 13, in simple_mp.masking_test
    simple_wm[mask==0] = 1
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Python 3.6 cython 0.29a0 numpy 1.16.0.dev0+2804c03

How can I resolve this problem? Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
skoudorocommented, Jun 28, 2018

Yes, it works with Cython 0.28.3 and numpy 1.16.0.dev0+2804c03.

1reaction
gabrieldemarmiessecommented, Jun 28, 2018

My apologies. You are totally right. I managed to reproduce the error with python 3.6, cython master and numpy 1.14.5. I’m going to investigate and see if an earlier version of cython or numpy does the trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: numpy.ufunc size changed, may indicate binary ...
python - ValueError: numpy. ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject - Stack ...
Read more >
NumPy 1.21.0 Release Notes
The Python versions supported for this release are 3.7-3.9. ... (Was deprecated in NumPy 1.16.) (gh-17900) ... Raises ValueError if low > high...
Read more >
NumPy 1.16.6 Release Notes
The NumPy 1.16.6 release fixes bugs reported against the 1.16.5 release, and also backports several enhancements from master that seem appropriate for a ......
Read more >
NumPy 1.15.0 Release Notes
NumPy 1.16 will drop support for Python 3.4. ... and the exceptions for non-square matrices have been changed to LinAlgError (from ValueError )....
Read more >
NumPy 1.20.0 Release Notes
For example, the following used to incorrectly give ValueError: operands could ... The fix is to either compile against 1.16.6 (if the NumPy...
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