values change in python as in REFERENCE????

Sort matrix values by absolute value abs(Lambda1)<abs(Lambda2)
it's not working i should have in the end both -9 and -10 in Lambda2 and -4 and -6 in Lambda1.
the problem is that i am having -4 and -6 in both matrices!!!
from numpy import *

mu1 = array([[1,2,-9],[4,5,-10],[7,8,9]])
mu2 = array([[1,2,-4],[4,5,-6],[7,8,9]])
check=abs(mu1) > abs(mu2)
print check
Lambda1=mu1
Lambda1[check]=mu2[check]
Lambda2=mu2
Lambda2[check]=mu1[check]

Open in new window

dadadudeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peprCommented:
I am not sure what are you trying to do, but yes. Any assignment in Python means assigning a reference to the source object.
0
dadadudeAuthor Commented:
i want to switch the values in the matrices. meaning i want to compare every element in both matrices and put the greater one in Lambda2 and smaller in Lambda1.
so if i have:
A =
1 2 3 -11
9 2 4 8
0 9 2 3
B =
1 2 3 8
9 2 4 8
0 9 2 3

i should have in the end :
A =
1 2 3 8
9 2 4 8
0 9 2 3
and
B =
1 2 3 -11
9 2 4 8
0 9 2 3

you can clearly SEE that the values -11 and 8 have been switched in both matrices. that's IT.
0
peprCommented:
I do not know what code prints the A and B.  However, the upper code says on the lines 7 and 9:

Lambda1=mu1
...
Lambda2=mu2

This makes Lambda1 identical to mu1 (the same instance via another reference), and Lambda2 identical to mu2

This way, your code can be simplified to -- see below. Does it make sense, now?
from numpy import *

mu1 = array([[1,2,-9],[4,5,-10],[7,8,9]])
mu2 = array([[1,2,-4],[4,5,-6],[7,8,9]])
check=abs(mu1) > abs(mu2)

mu1[check]=mu2[check]
mu2[check]=mu1[check]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

peprCommented:
In other words, whatever the check is, the elements in mu1 will be set to the same values as the elements in mu2. The the line 8 in the last snippet assigns the same values back to mu2.  I.e. both matrices should contain the same values on the spots determined by check.
0
dadadudeAuthor Commented:
thank you. it's ok i solved the problem. Actually what i want is totally the opposite I want in the end to switch the values in matrix 1 that are greater than the values in matrix 2. I didn't know that python has a reference for r-values where as matlab doesn't. i just modified a little the code.

Thanks anyway
0
dadadudeAuthor Commented:
I SOLVED THAT QUESTION ON MY OWN!!!!!!!!!!!!!!!!!!
0
dadadudeAuthor Commented:
lol sorry they asked me to add a reason for 1000 TIMES lol take care thank you.
0
peprCommented:
OK. Next time, you can post the answer to your own question and accept it as a solution. Or, if nobody commented your question, you can simply delete it.
0
dadadudeAuthor Commented:
no problem. Thanks anyway. well u didn't help for nothing u deserve points. u helped me in a way.
Thank you.

until next time.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.