numpy/np-vectorize
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| NumPy | warning | none, edit by hand | All versions |
np.vectorize, np.frompyfunc and np.apply_along_axis still call a Python function once per value or slice. Where the function is arithmetic or a condition, write it on whole arrays.
@np.vectorizedef clipped(x): return min(x, 3.0) return np.minimum(x, 3.0)What the rule reports
Section titled “What the rule reports”The rule reports np.vectorize, np.frompyfunc and np.apply_along_axis, whether called or used as a decorator.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
Diagnostic message
Section titled “Diagnostic message”$F still calls the Python function once per value or once per slice, so it runs at the speed of a Python loop. Where the function is arithmetic or a condition, write it on whole arrays, for example with np.where or np.select.See all rules in the NumPy pack.