Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The variable gets updated while change in the source value #4937

Open
SenthilKumarMCH opened this issue Nov 9, 2024 · 0 comments
Open

The variable gets updated while change in the source value #4937

SenthilKumarMCH opened this issue Nov 9, 2024 · 0 comments
Labels

Comments

@SenthilKumarMCH
Copy link

Description of the current behavior
The variable gets updated while the source value of the variable changes after the assignment of the variables

Description of the expected behavior
The variable should not change when the source value changes after it is assigned.

What web browser you are using
It is done in the Chrome browser

Additional context

Example to explain the bug

X = np.array([[-16.1718, 495.4491],
[-139.3684, 397.6613],
[81.1637, -201.7584],
[59.0297, -308.5572],
[45.7631, -392.7569]]) # Initializing the array
print(X) # Printing the array
Fk=X[2,:] # Initialze a new variable Fk with X[2,:]
print('Fk=',Fk) # Printing the variable Fk
vv=[320, 500] # Initialize a new variable vv
X[2,:]=vv+X[2,:] # Updating the X[2,:]
print('X=',X) # printing the variable X
print('Fk=',Fk) # Printing the variable Fk

Output:
X= [[ -16.1718 495.4491]
[-139.3684 397.6613]
[ 81.1637 -201.7584]
[ 59.0297 -308.5572]
[ 45.7631 -392.7569]]
Fk= [ 81.1637 -201.7584]
X= [[ -16.1718 495.4491]
[-139.3684 397.6613]
[ 401.1637 298.2416]
[ 59.0297 -308.5572]
[ 45.7631 -392.7569]]
Fk= [401.1637 298.2416]

The X is initialized with some values. FK variable is initialized with the 2nd element of the X array (X[2,:]). Later, X[2,:] is updated with the new value of the sum of X[2,:] + vv. This update makes changes in X and Fk. However, the X[2,:] is assigned to Fk before updating the value of X[2,:]. It is expected that Fk shouldn't get changed while updating the value X[2,:].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant