Re: how to shrink a numarray array?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: how to shrink a numarray array?

From: Diez B. Roggisch <deets@web.de>
Date: Thu Jun 30 2005 - 23:16:04 CEST

Qiangning Hong wrote:
> To draw a large array of data on a small panel, I need to shrink it to a
> given size. e.g:
>
> To draw numarray.arange(10000) on a panel of width of 100, I only need
> to draw the points of (0, 100, 200, 300, ...) instead of (0, 1, 2, ...).
> So I need a method to shrink it to an 100-item array.
>
> x[::len(x)/panel_width] will not work. If the panel's width is 60, that
> expression will return an array of 61 elements.
>
> I believe there is an existing function in numarray to do this, however
> English is not my mother tongue and math is not my speciality, I can't
> find it in the document full of math terms...
>

You can do that with bresenham's algortithm. But that's been sooo long
since I did that the last time... The basic idea is that you us the
larger of the values (your columncount) as a threshold. The you do
msomething like this:

columncount = 600
image_width = 60
v = 0
cols_to_pick = [0]
for i in xrange(columncount):
     if v >= columncount:
         v -= columncount
         cols_to_pick.append(i)
     v += image_width

Maybe a better idea is to try and find image scaling algorithms -they
might even do filtering for you.

Diez
Received on Thu Sep 29 16:40:36 2005