[Numpy-discussion] Binning

Adrien Gaidon adnothing at gmail.com
Thu Dec 22 06:27:47 EST 2011


Hello Nicola,

I am not aware of a magical "one function" numpy solution (is there one
numpy gurus?).

I don't know if it's optimal, but here's how I usually do similar things.

I wrote a simple function that assigns points (any number of dimensions) to
a regular multi-dimensional grid. It is here:
https://gist.github.com/1509853 It is short, commented and should be
straightforward to use.

Once you have the assignments, you can:
- get the non-empty cell indexes with `np.unique(assignments)`
- retrieve the points assigned to a cell with `points[assignments ==
cell_index]`
- iterate over assignments to select the points you want for each cell.

Hope this helps,

Adrien

PS: This is one of the first times I post an answer on this list, so if I
did anything wrong, let me know. Numpy is such a wonderful thing and you
guys do such an amazing work, that I though it is time to give back at
least epsilon of what I got from you :-)

2011/12/22 Nicola Creati <ncreati at inogs.it>

> Hello,
>
> I have a cloud on sparse points that can be described by a Nx3 array (N
> is the number of points). Each point is defined by an x, y and z
> coordinate:
>
> x0 y0 z0
> x1 y1 z1
>   .    .    .
>   .    .    .
>   .    .    .
> xn yn zn
>
>
> I need to bin the cloud to a regular 2D array according to a desired bin
> size assigning to each cell (bin) the minimum z of all points that fall
> in that cell(bin). Moreover I need indexes of points that fall in each
> cell(bin).
>
> Is there any way to accomplish this task in numpy?
>
> Thanks.
>
> Nicola Creati
>
>
>
>
> --
> Nicola Creati
> Istituto Nazionale di Oceanografia e di Geofisica Sperimentale - OGS
> www.inogs.it Dipartimento di Geofisica della Litosfera Geophysics of
> Lithosphere Department CARS (Cartography and Remote Sensing) Research Group
> http://www.inogs.it/Cars/ Borgo Grotta Gigante 42/c 34010 Sgonico -
> Trieste - ITALY ncreati at ogs.trieste.it
> off.   +39 040 2140 213
> fax.   +39 040 327307
>
> _____________________________________________________________________
> This communication, that may contain confidential and/or legally
> privileged information, is intended solely for the use of the intended
> addressees. Opinions, conclusions and other information contained in this
> message, that do not relate to the official business of OGS, shall be
> considered as not given or endorsed by it. Every opinion or advice
> contained in this communication is subject to the terms and conditions
> provided by the agreement governing the engagement with such a client. Any
> use, disclosure, copying or distribution of the contents of this
> communication by a not-intended recipient or in violation of the purposes
> of this communication is strictly prohibited and may be unlawful. For Italy
> only: Ai sensi del D.Lgs.196/2003 - "T.U. sulla Privacy" si precisa che le
> informazioni contenute in questo messaggio sono riservate ed a uso
> esclusivo del destinatario.
> _____________________________________________________________________
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20111222/5b76abc8/attachment.html>


More information about the NumPy-Discussion mailing list