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

Favre Jean jfavre at cscs.ch
Wed Jul 8 05:21:22 EDT 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150708/78dbab42/attachment.html>


More information about the vtkusers mailing list