[Numpy-discussion] stumped numpy user seeks help

Stefan van der Walt stefan at sun.ac.za
Wed Aug 30 10:51:52 EDT 2006


On Tue, Aug 29, 2006 at 03:46:45PM -0700, Mathew Yeates wrote:
> My head is about to explode.
> 
> I have an M by N array of floats. Associated with the columns are 
> character labels
> ['a','b','b','c','d','e','e','e']  note: already sorted so duplicates 
> are contiguous
> 
> I want to replace the 2 'b' columns with the sum of the 2 columns. 
> Similarly, replace the 3 'e' columns with the sum of the 3 'e' columns.
> 
> The resulting array still has M rows but less than N columns. Anyone? 
> Could be any harder than Sudoku.

I attach one possible solution (allowing for the same column name
occurring in different places, i.e. ['a','b','b','a']).  I'd be glad
for any suggestions on how to clean up the code.

Regards
Stéfan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arsum.py
Type: text/x-python
Size: 572 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060830/45b6b4db/attachment-0001.py>


More information about the NumPy-Discussion mailing list