Python Forum
Write the Matrix2 by using Matrix1
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write the Matrix2 by using Matrix1
#14
(Jan-20-2022, 02:34 PM)ThiefOfTime Wrote: Puh, yeah I get your Problem. it works for one dimensional input, so like single values, because it doesn't effect the dimension of the matrix. But adding a vector changes that of course and since one would be changed into 3 dimensional and the others (at that point) are not, it will not put the changes into affect.
In that case we need a bit more tricky way. The good thing is that Symbol from sympy have a useful equals function and also numpy can work with sympy.
also numpy has a function called where.
so if we convert your lists to numpy arrays instead of Matrices we will be able to search for objects in the other array. after that i would suggest you replace the value in the list objects since arrays in numpy are vectors/matrices and therefore have fix dimensions.
so:
import numpy as np
count = 0
rho_final_arr = np.array(rho_final)
for row in range(8):
    for column in range(8):
        if row==0 and column==0: count = 0
        else:    
            count+=1
        if count == 64: count = 63
        m = np.zeros((1,64))                         
        m[0][count]=1 
         
        if (rho_final[row][column]==rho[row][column]):
            print('hey')
            # i would leave this part as it is, as it is the fastest way to savely do what you are trying to do. also values that are succesfully found in both lists can be overwritten
            rho[row][column]=m
            rho_final[row][column]=m
        else:
            # searching for the symbol in the other list (will be a different object, but the name is the same)
            # also we are avoiding creating lookup tables or iterating through it more than necessary
            i, j = np.where(rho_final_arr == rho[row][column])
            rho[row][column]=m
            rho_final[int(i)][int(j)] = m
            
            
print('rho_final',rho_final[0][6])
i tested it with a small array, that should do the trick :)

Thanks for the answer!
I now have this error:
Error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
will find why I am having this and then come back to you. It is working for 7 times. after entering else loop, works one more run and then it stops and gives this error...
Reply


Messages In This Thread
Write the Matrix2 by using Matrix1 - by quest - Jan-19-2022, 12:20 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-19-2022, 11:43 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 08:20 AM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 11:37 AM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 11:54 AM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 12:29 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 11:18 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 11:58 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-22-2022, 12:41 AM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-23-2022, 11:57 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-24-2022, 01:07 AM

Forum Jump:

User Panel Messages

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