osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to multiply dictionary values with other values based on the dictionary's key?


> Do you want to modify the varsdict values in place?
> 
> varsdict['Feq_(i,_j,_k,_l)'] *= A[i,j,k,l]
> 
> which is a short-cut for this slightly longer version:
> 
> temp = varsdict['Feq_(i,_j,_k,_l)'] * A[i,j,k,l]
> varsdict['Feq_(i,_j,_k,_l)'] = temp
> 
> 
> 
> If you want to leave the original in place and do something else with the 
> result:
> 
> result = varsdict['Feq_(i,_j,_k,_l)'] * A[i,j,k,l]
> print(result)
> 

Thanks again for your answers Steven. I will try to explain it simpler because I think I tend to complicate things.

With your help I have arrived at this point:
I have the dictionary varsdict as below
Key                        Type        Size     Value 
FEq_(0,_0,_0,_0)           float        1        1.0 
FEq_(0,_0,_1,_1)           float        1        1.0 
FEq_(0,_0,_2,_2)           float        1        1.0 
FEq_(0,_0,_3,_0)           float        1        1.0 
FEq_(0,_0,_4,_1)           float        1        1.0 

and the dictionary A as below
Key                        Type        Size     Value 
FEq_(0,_0,_0,_0)           float        1        1500
FEq_(0,_0,_0,_1)           int1        0
... 
FEq_(0,_0,_1,_1)           float        1        3300
... 
FEq_(0,_0,_2,_2)           float        1        1.0 
FEq_(0,_0,_3,_0)           float        1        1.0 
FEq_(0,_0,_4,_1)           float        1        1.0