I want to add the following lists as elements into a NumPy matrix so that later on, I could eliminate some rows and columns.
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (5, 5) + inhomogeneous part.
import numpy as np
import math
import sympy as sp
def FSDT(a,b,E11,E22,Nu12,Nu21,G12,G13,G23,theta,PlyNumber,K,h):
#----------------------------------------------------------
i=0
h = PlyNumber*LaminaThickness
Z = []
Z.append(-h/2.0)
for j in range(1,PlyNumber+1,1):
Z.append(Z[j-1]+LaminaThickness)
#Matrix Q
Q11=[]
Q12=[]
Q22=[]
Q66=[]
Q44=[]
Q55=[]
Q11_B = []
Q12_B = []
Q16_B = []
Q22_B = []
Q26_B = []
Q66_B = []
Q44_B = []
Q45_B = []
Q55_B = []
for i in range(0,1,1):
Q11.append(E11/(1-Nu12*Nu21))
Q12.append((Nu12*E22)/(1-Nu12*Nu21))
Q22.append((E22)/(1-Nu12*Nu21))
Q44.append(G23)
Q66.append(G12)
Q55.append(G13)
i=0
for j in range(0,PlyNumber,1):
Q11_B.append(Q11[i]*(np.cos(theta[j]*np.pi/180.0)**4)+2*(Q12[i]+2*Q66[i])* (np.sin(theta[j]*np.pi/180.0))**2*(np.cos(theta[j]*np.pi/180.0))**2+Q22[i]*(np.sin(theta[j]*np.pi/180.0))**4)
Q12_B.append((Q11[i]+Q22[i]-4*Q66[i])*(np.sin(theta[j]*np.pi/180.0))**2*(np.cos(theta[j]*np.pi/180.0))**2+Q12[i]*((np.sin(theta[j]*np.pi/180.0))**4+((np.cos(theta[j]*np.pi/180.0))**4)))
Q16_B.append((Q11[i]-Q12[i]-2*Q66[i])*np.sin(theta[j]*np.pi/180.0)*np.cos(theta[j]*np.pi/180.0)**3+(Q12[i]-Q22[i]+2*Q66[i])*np.cos(theta[j]*np.pi/180.0)*np.sin(theta[j]*np.pi/180.0)**3)
Q22_B.append(Q11[i]*np.sin(theta[j]*np.pi/180.0)**4+2*(Q12[i]+2*Q66[i])*np.sin(theta[j]*np.pi/180.0)**2*np.cos(theta[j]*np.pi/180.0)**2+Q22[i]*np.cos(theta[j]*np.pi/180.0)**4)
Q26_B.append((Q11[i]-Q12[i]-2*Q12[i])*np.sin(theta[j]*np.pi/180.0)**3*np.cos(theta[j]*np.pi/180.0)+(Q12[i]-Q22[i]+2*Q66[i])*np.cos(theta[j]*np.pi/180.0)**3*np.sin(theta[j]*np.pi/180.0))
Q66_B.append((Q11[i]+Q22[i]-2*Q12[i]-2*Q66[i])**np.sin(theta[j]*np.pi/180.0)**2**np.cos(theta[j]*np.pi/180.0)**2+Q66[i]*(np.sin(theta[j]*np.pi/180.0)**4+np.cos(theta[j]*np.pi/180.0)**4))
Q44_B.append(Q44[i]*np.cos(theta[j]*np.pi/180.0)**2 + Q55[i]*np.sin(theta[j]*np.pi/180.0)**2)
Q55_B.append(Q44[i]*np.sin(theta[j]*np.pi/180.0)**2 + Q55[i]*np.cos(theta[j]*np.pi/180.0)**2)
Q45_B.append((Q55[i]-Q44[i])*np.cos(theta[j]*np.pi/180.0)*np.sin(theta[j]*np.pi/180.0))
Q = np.matrix([[Q11_B, Q12_B, Q16_B, 0, 0],[Q12_B, Q22_B, Q26_B, 0, 0],[Q16_B, Q26_B, Q66_B, 0, 0],[0, 0, 0, Q44_B, Q45_B],[0, 0, 0, Q45_B, Q55_B]])
return Q
#-----------------------------------------------------------------------------------------------
# def FSDT(E11,E22,G12,G13,G23,Nu12,Nu21,LaminaThickness,PlyNumber):
a = 10
b = 5
E11 = 131000
E22 = 32750
Nu12 = 0.25
Nu21 = 0.33
G12 = 19785
G13 = 16854
G23 = 19785
rho = 1650
K= np.pi**2/12
theta = [0,90,0,90,0]
PlyNumber = len(theta)
LaminaThickness = 0.01
h = 0.5
Q = FSDT(a,b,E11,E22,Nu12,Nu21,G12,G13,G23,theta,PlyNumber,K,h)
Or there is another way I could write the Q matrix??
Thank you for replying
I have tried to use np. array np. mat to define Q, but the same problem keeps occurring when running the code, it seems like the Q matrix is inhomogeneous.
Q = np.matrix(..., dtype=object)no error and no warning for meValueErrorlike you described. Do you know what your expected output array shape should be? Also, could you share more context on what you're trying to accomplish? That may help decipher your code and properly refactor.