Skip to content

numpy/power-half

Rule power-half
Pack NumPy
Severity warning
Fix unsafe, with xpd check --fix --unsafe-fixes
Library versions every version

np.power(x, 0.5) runs the general power function, which was 2 times slower. Call np.sqrt.

root = np.power(area, 0.5)
root = np.sqrt(area)

The rule reports np.power(x, 0.5).

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The unsafe fix writes np.sqrt(x).

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

np.power with 0.5 runs the general power function, which ran 2 times slower on 1,000,000 values. Write $NP.sqrt($X).

Browse the other rules of the NumPy pack.