Skip to content

numpy/power-half

Pack Severity Fix Versions
NumPy warning unsafe, with xpd check --fix --unsafe-fixes All versions

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

np.sqrt can return float16 or float32 on small integer dtypes where np.power(x, 0.5) returns float64.

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

See all rules in the NumPy pack.