Adam Black
Adam Black

Reputation: 53

invalid value encountered in power

Python 3. Following code says:

25: RuntimeWarning: invalid value encountered in power
  L[i] = (((volume*(10**6))*4*(F**2))/(C*pi))**(1/3)         #ft

The error is encountered at L[1,22] to L[1,30] and L[2,15] to L[2,30]

Is it part of the loop? I can copy and paste volume=22 and F=5 and it comes up with the number just fine.

lo     = 0.06521                                              # lbm/ft^3
volume = np.arange(0,31)                                      # M ft^3
lift   = volume*10**6*lo                                      # lbm
lift   = lift/2000                                            # ton


C = 0.6                                                       # Cylindrical Coefficient
pi = np.pi

L  = np.zeros((3,len(volume)))                         
for F in range(4,7):
   i   = F - 4
   L[i] = (((volume*(10**6))*4*(F**2))/(C*pi))**(1/3)         #ft

Upvotes: 4

Views: 223

Answers (2)

Jakub
Jakub

Reputation: 549

You have a scalar overflow problem. Specifying volume as int64 solves the problem.

volume = np.arange(31, dtype=np.int64)

Upvotes: 1

JimmyCarlos
JimmyCarlos

Reputation: 1952

If I rewrite the problem like this:

L  = np.zeros((3,len(volume)))                         
for F in range(4,7):
    i   = F - 4
    D = (((volume*(10**6))*4*(F**2))/(C*pi))
    L[i] =  D ** (1 / 3)

I can see that at F = 5, I get negative values for some parts of D.

These numbers cube rooted become complex, raising the error.

Upvotes: 0

Related Questions