I have a pretty big numpy array ...
power = ...
print power.shape
>>> (3, 10, 10, 19, 75, 10, 10)
which is symmetrical wrt 10 × 10 parts, i.e. the following 2-d matrices are symmetric.
power[i, :, :, j, k, l, m]
power[i, j, k, l, m, :, :]
for all values of i, j, k, l, m
Can I use this factor of 4? For instance. when saving the matrix to a file (50 mb with savez_compressed)
My attempt:
size = 10
row_idx, col_idx = np.tril_indices(size)
zip_idx = zip(row_idx, col_idx)
print len(zip_idx), zip_idx[:5]
>>> 55 [(0, 0), (1, 0), (1, 1), (2, 0), (2, 1)]
all_idx = [(r0, c0, r1, c1) for (r0, c0) in zip_idx for (r1, c1) in zip_idx]
print len(all_idx), all_idx[:5]
>>> 3025 [(0, 0, 0, 0), (0, 0, 1, 0), (0, 0, 1, 1), (0, 0, 2, 0), (0, 0, 2, 1)]
a, b, c, d = zip(*all_idx)
tril_part = np.transpose(s.power, (0, 3, 4, 1, 2, 5, 6))[:,:,:, a, b, c, d]
print tril_part.shape
>>> (3, 19, 75, 3025)
It seems ugly, but it works ... as soon as I can get back to power from tril_part again ...
I assume this gives two questions:
- Best way to go from power to tril_part?
- How to switch from tril_part to power?
Edit: the comment "size" is clearly valid, but please ignore it :-) IMHO. The indexing part of the question is one. I found that I want to do similar indexing for smaller matrices.