Skip to content

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.vectorize
def clipped(x):
return min(x, 3.0)
return np.minimum(x, 3.0)

The rule reports np.vectorize, np.frompyfunc and np.apply_along_axis, whether called or used as a decorator.

xpd has no automatic fix, so make the change by hand.

$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.