dadadude
asked on
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!!!
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]
I am not sure what are you trying to do, but yes. Any assignment in Python means assigning a reference to the source object.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Thanks anyway
ASKER
I SOLVED THAT QUESTION ON MY OWN!!!!!!!!!!!!!!!!!!
ASKER
lol sorry they asked me to add a reason for 1000 TIMES lol take care thank you.
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.
ASKER
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.
Thank you.
until next time.