-
Notifications
You must be signed in to change notification settings - Fork 67
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
How to reshape a matrix to a vector #59
Comments
This sounds more like a "permute" than a "reshape". You can do what you want by first splitting each core A_k(i_k, j_k) into two consecutive cores B_k(i_k) C_k(j_k), then move all B cores to the beginning and all C cores to the end using ttpy's new permute() function from the tools.py module. |
This can be done using combination of reshape and permute functions (both are in tools.py): def mat2vec(A):
crs_mat = tt.matrix.to_list(A)
crs_vec = []
for cr in crs_mat:
r1, n, m, r2 = cr.shape
crs_vec.append(cr.reshape(r1, n*m, r2, order='f'))
return tt.vector.from_list(crs_vec)
n = 2
d = 6
A = tt.eye([n]*d)
A = mat2vec(A)
A = tt.reshape(A, [2]*2*d)
A = tt.permute(A, range(0, 2*d, 2) + range(1, 2*d+1, 2), 1e-10) P.S.: permuting the identity matrix this way is a bad idea, but still :) |
Thanks, Raffaele |
Note however, that it contains |
Thanks again. umax = maxval(abs(mat(1:(min(nn,mm)+(nn-1)mn)))) ! new line I did something similar in ztt_ort(). |
@rakhuba |
The problem is that in my example the resulting matrix will have full rank independently of the method you choose to get it. I do not know your particular application, so there is not much can be said here. |
Indeed that reshape has full rank. Once I realized it I reformulated my entire problem to avoid the reshape/permute operations. Thanks for the hints. |
Is it possible to use the implemented reshape function to reshape a matrix to a vector? I have a matrix A(i_1, ...i_d, j_1...j_d) in TT format and I want to reshape it to a vector with the following structure:
A = A_1(i_1,j_1) A_2(i_2,j_2) ... -> B_1(i_1) B_1(i_2)...B_d(i_d) B_{d+1}(j_1) ...B_{2d}(j_d)
The reshape function of a matrix seems to work only with a pair of indices, and I cannot find an example of tensor reshaping.
Thanks.
The text was updated successfully, but these errors were encountered: