Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Give a number for Variable
#1
I defined symbols via Sympy and I created an array. Then when I want to give a value to the variable, the variable still stay as variable.

a, b, c, d = sympy.symbols('a b c d')
error_mat=np.array([[a+d,b-c*1j],[b+c*1j,a-d]])
error_mat.shape
Then, after I found the correct values for my variables, I simply say that:

a=0.9685
b=0.0315
print(error_mat)
#error_mat.subs(a, 0.9685)
#error_mat.subs(b, 0.0315)
But my matrix is still:

[[a + d b - 1.0*I*c]
 [b + 1.0*I*c a - d]]
How can I update the variables?
Reply
#2
After line 2 in 2nd code set you need to re-run
code error_mat=np.array([[a+d,b-c*1j],[b+c*1j,a-d]])
BashBedlam and quest like this post
Reply
#3
Or else have a look at eval().
BashBedlam likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  optimum chess endgame with D=3 pieces doesn't give an exact moves_to_mate variable max22 1 251 Mar-21-2024, 09:31 PM
Last Post: max22
  Give visit number ( or counter) within the same time frame balthordu 1 938 Jun-27-2022, 09:51 AM
Last Post: Larz60+
  [solved] Variable number of dictionnaries as argument in def() paul18fr 11 6,111 Apr-20-2021, 11:15 AM
Last Post: paul18fr
  How to verify the give number is valid Mekala 3 2,393 May-16-2020, 02:40 PM
Last Post: anbu23
  [regex] Good way to parse variable number of items? Winfried 4 2,607 May-15-2020, 01:54 PM
Last Post: Winfried
  Add two number and variable datatype is int8 ift38375 3 2,917 Aug-05-2019, 05:41 PM
Last Post: DeaD_EyE
  joining a variable number of lists in a comprehension Skaperen 2 2,804 Oct-14-2017, 08:19 AM
Last Post: Skaperen
  How give an for loop an maximum number, help pleace ? JamieVanCadsand 3 3,543 Aug-09-2017, 08:15 AM
Last Post: JamieVanCadsand

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020