segment_combine() fails with ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
See original GitHub issuesegment_combine() fails with ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
minimal code to reproduce:
import numpy as np
from plantcv import plantcv as pcv
#works:
segs = [np.array([[[1,2]], [[3,4]]]), np.array([[[5,6]], [[7,8]]]), np.array([[[9,10]], [[11,12]]])]
pcv.morphology.segment_combine([0,1], segs, np.zeros((100,100),dtype=np.uint8))
#fails:
segs = [np.array([[[1,2]], [[3,4]]]), np.array([[[5,6]], [[7,8]]]), np.array([[[9,10]], [[11,12]]])]
pcv.morphology.segment_combine([1,2], segs, np.zeros((100,100),dtype=np.uint8))
full error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
[<ipython-input-101-7ac3bd532796>](https://localhost:8080/#) in <module>()
8 #fails:
9 segs = [np.array([[[1,2]], [[3,4]]]), np.array([[[5,6]], [[7,8]]]), np.array([[[9,10]], [[11,12]]])]
---> 10 pcv.morphology.segment_combine([1,2], segs, np.zeros((100,100),dtype=np.uint8))
[/usr/local/lib/python3.7/dist-packages/plantcv/plantcv/morphology/segment_combine.py](https://localhost:8080/#) in segment_combine(segment_list, objects, mask)
42 new_objects = all_objects[segment_list[0]]
43 # Remove the objects getting combined from the list of all objects
---> 44 all_objects.remove(objects[segment_list[0]])
45
46 while count < num_contours:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Local environment:
- OS: Linux
- Environment: google colab, python 3.7
- PlantCV Version 3.14.1
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ValueError: The truth value of an array with more than one ...
array ([1,2]): print(1) --> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() ....
Read more >How to Fix “ValueError: The truth value of an array with more ...
The output will be this error message: # Output: ValueError: The truth value of an array with more than one element is ambiguous....
Read more >The truth value of an array with more than one ... - sopython
The truth value of an array with more than one element is ambiguous. ... That x<5 is not actually a boolean value, but...
Read more >NumPy, pandas: How to fix ValueError: The truth value ... is ...
Use a.any() or a.all() # a_bool and b_bool # ValueError: The truth value of an array with more than one element is ambiguous....
Read more >The truth value of an array with more than one element is ...
"ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
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
thanks! if you want to do it in place you could find the indices to be removed and then loop in reverse order from the end. or you could just create a new list. will share soon 😃
I did some testing this morning and wanted to share the updated
combine_segments
function with you for further testing! Please let me know if this functionality works for your data.