473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

numpy: frequencies

I have an integer array with values limited to range(a,b) like:

ia=array([1,2,3,3,3,4,...2,0,1])

and want to speedly count the frequencies of the integers into get a density matrix.
Is this possible without looping?
Question 2: is it possible to compute a "moving maximum" without python looping

ia=array([4,2,1,5,3,2,2,0,1,1])
-mvmax(ia,3) ->
[4,4,4,5,5,5,3,2,2,1])
Robert
Nov 18 '06 #1
2 2205
robert wrote:
I have an integer array with values limited to range(a,b) like:

ia=array([1,2,3,3,3,4,...2,0,1])

and want to speedly count the frequencies of the integers into get a density matrix.
Is this possible without looping?
See numpy.bincount (for integers >= 0) if you mean 'without writing
looping code in Python' or please specify your question.
Question 2: is it possible to compute a "moving maximum" without python looping

ia=array([4,2,1,5,3,2,2,0,1,1])
-mvmax(ia,3) ->
[4,4,4,5,5,5,3,2,2,1])
I haven't seen a ready solution but this can be easily converted into
Pyrex/C looping.

cheers,
fw

Nov 18 '06 #2
Filip Wasilewski wrote:
robert wrote:
>I have an integer array with values limited to range(a,b) like:

ia=array([1,2,3,3,3,4,...2,0,1])

and want to speedly count the frequencies of the integers into get a density matrix.
Is this possible without looping?

See numpy.bincount (for integers >= 0) if you mean 'without writing
looping code in Python' or please specify your question.
>Question 2: is it possible to compute a "moving maximum" without python looping

ia=array([4,2,1,5,3,2,2,0,1,1])
-mvmax(ia,3) ->
[4,4,4,5,5,5,3,2,2,1])

I haven't seen a ready solution but this can be easily converted into
Pyrex/C looping.
I don't know a way to avoid looping entirely, but there are ways that
you can loop over the width of the window (in this case 3) rather than
over the entire array. Since the window width is generally small
compared to the array, this will probably be fast enough. The tricky
part is to get the value right at the edges, since what you do there
depends on what boundary conditions you apply.

The general idea is this:

result = ia[n-1:]
for i in range(n-1):
numpy.maximum(result, ia[i:-n+i], result)

This punts on dealing with the ends (and I haven't tested this version),
but should give you the idea.

-tim

Nov 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Giovanni Ciampaglia | last post by:
Hello everyone, Could someone explain me what is the "steady-state" value contained into the array returned by FFT.fft(data,n=None,axis=-1) at its first position? Is it one of the values...
13
by: Gary Wessle | last post by:
Hi I am trying to install NumPy in my debian/testing linux 2.6.15-1-686. with no numpy for debian/testing, I am left alone, since the experimental version available by debian will result in a...
3
by: Iljya | last post by:
Hello, I need to pickle the type numpy.float32 but encounter an error when I try to do so. I am able to pickle the array itself, it is specifically the type that I cannot pickle. I am using:...
0
by: robert | last post by:
just a note - some speed comparisons : 0.60627370238398726 0.42836673376223189 0.36965815487747022 0.016557970357098384 0.15692469294117473 0.01951756438393204
2
by: robert | last post by:
in Gnuplot (Gnuplot.utils) the input array will be converted to a Numeric float array as shown below. When I insert a numpy array into Gnuplot like that below, numbers 7.44 are cast to 7.0 Why is...
2
by: Chris Smith | last post by:
Howdy, I'm a college student and for one of we are writing programs to numerically compute the parameters of antenna arrays. I decided to use Python to code up my programs. Up to now I haven't...
5
by: robert | last post by:
Turning algs for old NumPy modules into numpy code I suffer from this: Upon further processing of returns of numpy calculations, lots of data in an apps object tree will become elementary numpy...
35
by: rajash | last post by:
Hello everyone, Thanks again for all the suggestions, though I think some people are a bit fussy in their answers. Here is a solution to Exercise 1.14. It deals well with control characters...
2
by: Travis Oliphant | last post by:
I wanted to point anybody interested to a blog post that describes a useful pattern for having a NumPy array that points to the memory created by a different memory manager than the standard one...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.