vtkmodules.numpy_interface.vtk_indexed_array#
VTKIndexedArray — numpy-compatible mixin for vtkIndexedArray.
This module provides the VTKIndexedArray mixin class and registers overrides for all vtkIndexedArray instantiations so that indexed arrays coming from VTK automatically have numpy-compatible operations.
A vtkIndexedArray provides reindexed access to a base array via an
index list: result[i] = base_array[index_array[i]]. It is used
in HyperTree filters and probe filters for zero-copy subset views.
Materialization uses efficient numpy fancy indexing:
numpy.asarray(base)[numpy.asarray(indexes)]. Reductions delegate
to the materialized array since there is no closed-form shortcut for
arbitrary index subsets.
Module Contents#
Classes#
A numpy-compatible mixin for indexed (reindexed subset) implicit arrays. |
Functions#
Register VTKIndexedArray mixin as override for all vtkIndexedArray template types. |
API#
- class vtkmodules.numpy_interface.vtk_indexed_array.VTKIndexedArray(indexes=None, array=None, **kwargs)#
Bases:
vtkmodules.numpy_interface._vtk_array_mixin.VTKDataArrayMixinA numpy-compatible mixin for indexed (reindexed subset) implicit arrays.
vtkIndexedArraystores a base array and an index array, presentingbase[indexes[i]]as a virtual array. This Python mixin adds numpy integration: arithmetic, reductions, indexing, andto_numpy().Initialization
Create an indexed array.
Parameters
indexes : vtkDataArray, optional Index array for indirection. array : vtkDataArray, optional Base array to index into. **kwargs Forwarded to the VTK base-class initializer.
- property base_array#
Return the original base array used for value lookup.
- property index_array#
Return the original index array used for indirection.
- property dtype#
- property nbytes#
- to_numpy(dtype=None)#
Materialize the full array as a numpy ndarray.
- __array__(dtype=None, copy=None)#
Materialize the full array via numpy fancy indexing.
- __buffer__(flags)#
Override C-level buffer protocol to materialize via array.
- _new_indexed(new_base_np)#
Create a new VTKIndexedArray with the same indexes but a new base.
Parameters
new_base_np : numpy.ndarray The transformed base array (flat values).
Returns
VTKIndexedArray or None A new indexed array, or None if the dtype is unsupported.
- __array_ufunc__(ufunc, method, *inputs, **kwargs)#
Handle numpy ufuncs, staying lazy when possible.
For unary ufuncs and binary ufuncs with a scalar operand, the ufunc is applied to the base array and a new indexed array is returned with the same index mapping — no materialization needed.
For binary ufuncs with another array operand, the indexed array is materialized since the other array’s elements don’t align with the base.
- __array_function__(func, types, args, kwargs)#
Dispatch numpy functions via override registry.
- _sub_index_array(tuple_indices)#
Build a new value-level index array for the given tuple indices.
Parameters
tuple_indices : array-like of int Which tuples to select.
Returns
numpy.ndarray Flat value-level indices into the base array.
- _new_from_sub_indexes(new_idx_np)#
Create a new VTKIndexedArray with sub-selected indexes, same base.
Parameters
new_idx_np : numpy.ndarray New value-level index array (flat).
Returns
VTKIndexedArray or None
- __getitem__(key)#
Index into the indexed array.
Scalar index: direct lookup, no materialization. Slice / fancy int / boolean mask on axis 0: compose a new index array pointing at the same base — stays lazy. Tuple indexing (row, col) or other: materialize.
- __setitem__(key, value)#
- __add__(other)#
- __radd__(other)#
- __sub__(other)#
- __rsub__(other)#
- __mul__(other)#
- __rmul__(other)#
- __truediv__(other)#
- __rtruediv__(other)#
- __floordiv__(other)#
- __rfloordiv__(other)#
- __pow__(other)#
- __rpow__(other)#
- __mod__(other)#
- __rmod__(other)#
- __lt__(other)#
- __le__(other)#
- __eq__(other)#
- __ne__(other)#
- __ge__(other)#
- __gt__(other)#
- __neg__()#
- __pos__()#
- __abs__()#
- sum(axis=None, **kwargs)#
- min(axis=None, **kwargs)#
- max(axis=None, **kwargs)#
- mean(axis=None, **kwargs)#
- std(axis=None, **kwargs)#
- var(axis=None, **kwargs)#
- any(axis=None, **kwargs)#
- all(axis=None, **kwargs)#
- prod(axis=None, **kwargs)#
- __iter__()#
- __repr__()#
- __str__()#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_sum(a, axis=None, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_mean(a, axis=None, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_min(a, axis=None, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_max(a, axis=None, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_std(a, axis=None, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_var(a, axis=None, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_any(a, axis=None, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_all(a, axis=None, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_prod(a, axis=None, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._indexed_concatenate(arrays, axis=0, **kwargs)#
- vtkmodules.numpy_interface.vtk_indexed_array._register_indexed_overrides()#
Register VTKIndexedArray mixin as override for all vtkIndexedArray template types.