I work on a Python 3.11 program and I have this error:
Traceback (most recent call last):
File "C:\Users\LWWB0754\OneDrive - orange.com\Docs\Égalisation\Python Version\Wiener Filter\main.py", line 14, in <module>
symb = [random.choice(A) for _ in range(nbsymb)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\LWWB0754\OneDrive - orange.com\Docs\Égalisation\Python Version\Wiener Filter\main.py", line 14, in <listcomp>
symb = [random.choice(A) for _ in range(nbsymb)]
^^^^^^^^^^^^^^^^
File "C:\Users\LWWB0754\AppData\Local\Programs\Python\Python311\Lib\random.py", line 369, in choice
if not seq:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
When I run this simple code:
import numpy as np
import random
nbsymb = 8
M = 16
A = np.arange(-np.sqrt(M)+1, np.sqrt(M), 2)
symb = [random.choice(A) for _ in range(8)]
>Solution :
Sounds like this is due to a regression in Python 3.11 which was later fixed. Upgrade to Python >=3.11.2
Numpy has its own random stuff, perhaps you should use that instead: https://numpy.org/doc/stable/reference/random/
If for some reason you can’t upgrade, choose random elements from a list instead of a numpy array:
A = list(np.arange(-np.sqrt(M)+1, np.sqrt(M), 2))
symb = [random.choice(A) for _ in range(nbsymb)]