Python power with negative values returns error

Viewed 45

I'm having trouble with powers with negative numbers: sometimes it gives me error, sometimes it does it without warnings or errors.

import numpy as np

FS = 1.28
X = (np.arange(20) / FS)[np.newaxis]

Y = np.real((X.T @ X) ** (-0.5))

for i in range (0,  20, 1):
        for j in range (0,  20, 1):
                print(Y[i][j])

This code doesn't give any problems.

This other one, instead, returns error:

W = np.real(((W @ W.T)**(-0.5)) @ W)

W is 2x128 matrix.

The error is:

W = np.real(((W @ W.T)**(-0.5)) @ W)
RuntimeWarning: invalid value encountered in power

in both cases I've made operations with a matrix and the same power, why in the second case it returns error ?

0 Answers
Related