[SciPy-user] Triangular Matrix, Matrix Manipulations
Ed Schofield
schofield at ftw.at
Fri Jun 9 01:31:20 CDT 2006
On 08/06/2006, at 11:57 PM, Chris Lasher wrote:
> Hi all,
>
> ...
>
> I am interested in learning if a triangular matrix (lower or upper,
> does not matter to me) structure exists in SciPy or NumPy. I'd like to
> work with DNA or protein distance matrices, which are symmetric about
> the central axis ([0][0] to [n][n]) and such a structure might help
> greatly.
>
> The main two things I am looking to do are:
> * Tally the number of entries in a matrix that are equal to or
> greater/less than a specified value.
> * Randomly shuffle the values in a matrix.
>
> I'm interested in using an approach with these libraries to keep
> memory usage and execution times lower, as some of these distance
> matrices can be thousands x thousands of sequences. A triangular
> matrix structure might be nice to halve the amount of iteration and
> also make it easier to randomly shuffle the values (since a square
> matrix requires the values to be shuffled symmetrically, or to be
> built from scratch one value at a time).
Are the upper triangles of your matrices sparse? If not, I suggest
you use dense arrays, since the memory overhead will only be a factor
of two and implementing it will be easier.
SciPy doesn't currently have a symmetric sparse matrix format, but
this probably wouldn't help with your problem anyway; the CSR or CSC
type should serve you just as well. The first point you mentioned is
easy to support with these types, but the second could be problematic
unless the shuffle keeps the zeros in the same places ...
-- Ed
More information about the SciPy-user
mailing list