To the best of my knowledge,tqdm
does not wrap over numpy.vectorize
.
To display the progress bar for numpy arrays, numpy.ndenumerate
can be used.
Given the inputs and function:
import numpy as np
from tqdm import tqdm
a = np.array([1, 2, 3, 4])
b = 2
def myfunc(a, b):
"Return a-b if a>b, otherwise return a+b"
if a > b:
return a - b
else:
return a + b
Replace this vectorised part below
# using numpy.vectorize
vfunc = np.vectorize(myfunc)
vfunc(a, b)
with this
# using numpy.ndenumerate instead
[myfunc(x,b) for index, x in tqdm(np.ndenumerate(a))]
To see the tqdm
progress.