简体   繁体   中英

ValueError: setting an array element with a sequence symbolic

I am beginner with python. I have the following code:

import Deformation
import Qtheta
import numpy as np
import sympy as sp

def champs_de_contraintes(epaisseurs,angles,El,Et,Glt,Nult):
    E0=np.mat('[0;0;0]') #inizialising E0
    K=np.mat('[0;0;0]')   #inizialising K 
    E0K=np.mat('[0;0;0;0;0;0]') #inizialising K 
    E0K = Deformation.defos(epaisseurs,angles,El,Et,Glt,Nult) #function that return a 6x1 matrix type <class 'numpy.matrixlib.defmatrix.matrix'>
    E0=E0K[:3]   #Slicing E0K into 2 vectors E0 and K
    K=E0K[3:]
    nb_composantes = 3 #sigma x, sigma y, taux xy 
    Sigmaxy=np.zeros((nb_composantes,len(epaisseurs))) #sigma x, sigma y, taux xy, Array 

    #===============This bloc calculate the altitude of a ply =================   

    z=[]
    e=[]
    z.append(-(np.sum(epaisseurs))/2)
    for k in (range(len(epaisseurs))): #initialising e[k] 
        e[len(e):] = [0] #Values to add to get the altitude
    for i in (range(len(epaisseurs))):
        e[i]= e[i-1] + epaisseurs[i] #sum e
        z[len(z):] = [z[0] + e[i]] #Altitude

    #===========================This bloc calculate a vector===================
    for i in (range(len(epaisseurs))):
        newcolumn= Qtheta.Qtheta(angles[i],El,Et,Glt,Nult)*E0+z[i]*Qtheta.Qtheta(angles[i],El,Et,Glt,Nult)*K #z is the altitude
        #3x1 = 3x3*3x1 + 1x1*3x3*3x1
        for m in (range(len(newcolumn))):
            Sigmaxy[i,m]=newcolumn[m]
    return Sigmaxy

This returns me the error

Sigmaxy[i,m]=newcolumn[m]
ValueError: setting an array element with a sequence

Basically, what i want to do is to save the vector "newcolumn" in a newcolumn in the Sigmaxy matrix. I think that I get this error because "newcolumn" is symbolic. Actually, E0 and K depend on 2 variables.

Could anybody help me with this one ?

Thanks in advance !

If you want to set elements of your array in this way, you need to make sure that the shapes are matching.

The error you get is thrown if you try something like this:

my_1d_array = np.array([1,2,3])
my_1d_array[0] = [4, 5, 6]

As the error explains, you are trying to set a single element to a sequence of elements, which is not possible. Debug your code, and make sure that the shapes ( .shape ) of Sigmaxy[i,m] and newcolumn[m] are matching.

Initialize your array with the correct size with space for all the elements in the beginning. If you don't know the exact size, you can create bigger arrays by adding columns, see other questions for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM