[vtkusers] How to get the IDs of min and max from a GetRange() ?

Cory Quammen cory.quammen at kitware.com
Wed Jul 8 08:08:45 EDT 2015


Very nice, Jean.

On Wed, Jul 8, 2015 at 4:21 AM, Favre Jean <jfavre at cscs.ch> wrote:

>  my preference goes towards using numpy for this type to query
>
> use the where() function.
>
> # example 1:
>
> import vtk
> from vtk.numpy_interface import dataset_adapter as dsa
>
> # assuming your mesh data is in the object 'vtkgrid'
> np_grid = dsa.WrapDataObject(vtkgrid)
>
> # assuming your scalar variable is called 'scalars'
> np_scalars = np_grid.PointData['scalars']
>
> # min and max are:
> print np.min(np_scalars), np.max(np_scalars)
>
> #Their position(s) in the array is(are):
> np.where(np_scalars == np.max(np_scalars))
> np.where(np_scalars == np.min(np_scalars))
>
> # example 2:
>
> a = np.array([0, 0, 1, 2, 8, 9, 10, 9, 0, 0, 0, 9, 10, 9, 8, 6, 4, 3, 0,
> 0])
>
> In [51]: np.where(a == a.min())
> Out[51]: (array([ 0,  1,  8,  9, 10, 18, 19]),)
>
> In [52]: np.where(a == a.max())
> Out[52]: (array([ 6, 12]),)
>
> References:
>
> http://kitware.com/blog/home/post/714
>
>  -----------------
> Jean
> CSCS
>



-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150708/339d866b/attachment.html>


More information about the vtkusers mailing list