how to shrink a numarray array?

Q

Qiangning Hong

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...

--
Qiangning Hong

______________________________________________
( Michael: )
( )
( Hi. I'm Michael Jackson, from The Jacksons. )
( )
( Homer: I'm Homer Simpson, from the Simpsons. )
( )
( Stark Raving Dad )
----------------------------------------------
o
o \
\ /\
( )
.( o ).
 
D

Diez B. Roggisch

Qiangning said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,308
Members
47,956
Latest member
AmeeBerger

Latest Threads

Top