getting an error message: can't multiply sequence by non-int of type 'numpy.float64'

Viewed 25

I wrote this code to calculate the pressure, but I'm getting an error message says "can't multiply sequence by non-int of type 'numpy.float64' why I'm getting it? how can I fix it?

import numpy as np # create Q vector q1=0 q4=5064 list=[q1,0,0,q4] Q=np.array(list)

# Create Act matrix
Act= 8
Act_arr=np.array([Act,Act,Act,Act])
Act_diag = np.diag(Act_arr)
       
# Create J matrix
j1=0
j4=5.064
array = np.array([j1,0,0,j4])
J = np.diag(array)
        
# Create T matrix:
Tr= 2.532
def tridiag(a, b, c, k1=-1, k2=0, k3=1):
    return np.diag(a, k1) + np.diag(b, k2) + np.diag(c, k3)

a = [-Tr, -Tr, -Tr]; b = [Tr, 2*Tr, 2*Tr, Tr]; c = [-Tr, -Tr, -Tr]
T_tr = tridiag(a, b, c) 
dx=1
dt=5
x=np.arange(0,4, dx)
t=np.arange(0,20,dt)
BC=[3000,3000]
n=len(x)
m=len(t)
P=np.zeros((n,m))
P[0,:]=BC[0]
P[-1,:]=BC[0]
#theta=[0, 0.5, 1]
array_2=np.matrix([3000,3000,3000,3000])
IC=np.matrix(array_2)
print(IC)
for j in range(1,m):
    for i in range(1,n):
        P[:,0]=IC
       # sum1[i,j]=Act_diag[i,j] - theta*(T_tr[i,j]+J[i,j])
        #sum2[i,j]=(1- theta)*(T_tr[i,j]+J[i,j]) + Act_diag[i,j]
        P[i,j]=((Act_diag[i,j] - 0.5*(T_tr[i,j]+J[i,j]))/((1- 0.5)*(T_tr[i,j]+J[i,j]) + Act_diag[i,j]))*P[i,j] + Q[i]/((1- 0.5)*(T_tr[i,j]+J[i,j]) + Act_diag[i,j]) 
            
print(P)
  

  
       
    
0 Answers
Related