[SciPy-User] How Can I Bin A Matrix?

Joseph Smidt josephsmidt@gmail....
Thu Oct 29 08:58:27 CDT 2009


Hello,

     Lets pretend I have some random 100x100 matrix and I wanted to
form a 10x10 matrix where each element of the 10x10 matrix is the
average of the corresponding 10x10  block of the 100x100 matrix.

    To make this clearer, lets suppose I have a 4x4 matrix:

( 7, 2, 3, 4 )
( 9, 4, 5, 6 )
( 3, 5, 7, 9 )
( 1, 5, 2, 6 )

    and lets say I want to bin it to a 2x2 matrix meaning I want to
create a 2x2 matrix which would be:

(  5.5, 4.5 )
(  3.5, 6.0 )

where 5.5 is the average of the upper left block of the 16x16 matrix:

( 7, 2 )
( 9, 4 )

   and similarly with  the other elements.

   Anyways, given an arbitrary NxN matrix is the an easy way to bin it
to an MxM matrix where N is divisible by M?  If someone could come up
with code to do this I would be very grateful.

                  Joseph Smidt

-- 
------------------------------------------------------------------------
Joseph Smidt <josephsmidt@gmail.com>

Physics and Astronomy
4129 Frederick Reines Hall
Irvine, CA 92697-4575
Office: 949-824-3269


More information about the SciPy-User mailing list