NumPy, RuntimeWarning: invalid value encountered in power

Numpy does not seem to allow fractional powers of negative numbers, even if the power would not result in a complex number. (I actually had this same problem earlier today, unrelatedly). One workaround is to use

np.sign(a) * (np.abs(a)) ** (1 / 3)

Leave a Comment