numpy/np-vectorize
| Rule | np-vectorize |
|---|---|
| Pack | NumPy |
| Severity | warning |
| Fix | none, edit by hand |
| Library versions | every version |
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.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
$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.Browse the other rules of the NumPy pack.