Bonjour tous,
j'ai un problème que je trouve très bizarre, j'espère que vous pourrez m'expliquer qu'es ce qui ne va pas dans mon code car là je ne comprends plus du tout

Ci dessous vous allez voir dans ma fonction que j'ai un array qui s'appelle "Loadings", il est initialisé au début de la simulation et ensuite je n'y touche plus (je m'en sers juste comme entrée pour faire des petits calculs)

A mon grand étonnement lorsque je vais la vérification de son contenu (où je met le commentaire #verif1 en réalité il y a une fonction qui vérifie le contenu de Loading) je me rend compte qu 'il est modifié dans cette fonction

Et le truc que comprends encore moins c'est que si j'efface la ligne AllResultsHere[f][tp1][:]=np.copy(CurrentResultTp1) alors la matrice "Loadings" reste intacte comme je le souhaite

J'ai entendu dire qu'avec numpy on ne peux pas faire A=B (je ne sais pas pourquoi ) et qu'il faut faire A=np.copy(B) et c'est bien ce que j'ai fais donc je suis vraiment étonné d'avoir des soucis....

merci pour l'aide que vous pourrez me donner

bonne soirée

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    def allsimulations(self,Param,systemO,inputO,plotO,finalPlot):
        Loadings=np.asarray(inputO.allExpLoadMatrix)
        Results=np.asarray(inputO.allExpRsltMatrix)
        LoadingsOpt=np.asarray(inputO.allOptloadMatrix)
        ResultsOpt=np.asarray(inputO.allOptResultMatrix)
        AllResultsHere=np.asarray(inputO.allExpLoadMatrix)#np.copy(Loadings)
        Times=np.asarray(inputO.allTimeVector)
        ResultsIni=np.asarray(inputO.allInitialResults)
        ### 
        ### 
        #verif1
        ### 
        ### 
        tempCol=[]
        for i in range(0,len(inputO.iniAuxVariables),1):
            tempCol.append(inputO.iniAuxVariables[i])
        ListOfAux=[]
        for i in range(0,len(Loadings),1):
            tempLine=[]
            for j in range(0,len(Loadings[i]),1):
                tempLine.append(tempCol)
            ListOfAux.append(tempLine)
        AuxVar=np.asarray(ListOfAux)
        ### 
        ### 
        #verif2
        ### 
        ### 
        for f in range(0,len(Loadings),1):
            for tp1 in range(0,len(Times[f]),1):
                if tp1==0:
                    CurrentResultTp1=np.copy(ResultsIni[f][0][:])
                    CurrentAuxVarTp1=np.copy(AuxVar[f][0][:])
                else:
                    timeT=Times[f][tp1-1]
                    timeTp1=Times[f][tp1]
                    dTime=timeTp1-Times[f][tp1-1]
                    LoadT=np.copy(Loadings[f][tp1-1][:])
                    LoadTp1=np.copy(Loadings[f][tp1][:])
                    DLoad=np.copy(LoadTp1-Loadings[f][tp1-1][:])
                    DLoadDt=DLoad/dTime
                    ResultT=np.copy(CurrentResultTp1)
                    ResultTp1=np.copy(CurrentResultTp1)
                    AuxVarT=np.copy(CurrentAuxVarTp1)
                    AuxVarTp1=np.copy(CurrentAuxVarTp1)
                    sizeR=len(CurrentResultTp1)
                    sizeA=len(CurrentAuxVarTp1)
                    CurrentResultTp1=runC.simulation(self,Param,sizeR,sizeA,timeT,timeTp1,dTime,LoadT,LoadTp1,DLoad,DLoadDt,ResultT,ResultTp1,AuxVarT,AuxVarTp1)
                ### 
                ### 
                #verif3
                ### 
                ### 
                AllResultsHere[f][tp1][:]=np.copy(CurrentResultTp1)
                ### 
                ### 
                #verif4
                ### 
                ### 
        ##############
        return AllResultsHere