[Numpy-discussion] saving the lower half of matrix
Bala subramanian
bala.biophysics@gmail....
Mon Jun 17 06:07:34 CDT 2013
Friends,
I have to save only the lower half of a symmetric matrix to a file. I used
numpy.tril to extract the lower half. However when i use 'numpy.savetxt',
numpy saves the whole matrix (with upper half values replaced as zeros)
rather than only the lower half. Any better idea to achieve this.
as an example
>>>import numpy as np
>>> d=np.arange(1,26,1)
>>> d=d.reshape(5,5)
>>> np.tril(d)
array([[ 1, 0, 0, 0, 0],
[ 6, 7, 0, 0, 0],
[11, 12, 13, 0, 0],
[16, 17, 18, 19, 0],
[21, 22, 23, 24, 25]])
>>> np.savetxt( 'test', np.tril(d))
output test also contains the zeros, what i want is only the lower half
like below.
1
6 7
11 12 13
- - - - etc
Thanks,
Bala
--
C. Balasubramanian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130617/b27975dc/attachment.html
More information about the NumPy-Discussion
mailing list