[vtk-developers] Inconsistency in numpy_support
Prabhu Ramachandran
prabhu at aero.iitb.ac.in
Tue Jan 6 12:27:29 EST 2009
Hi Berk,
Berk Geveci wrote:
> I have been playing around with numpy-vtk array conversion. I think
> there is an inconsistency in the way numpy_support converts VTK arrays
> to numpy arrays. If the array has 1 component, vtk_to_numpy returns an
> array of shape (10,), whereas if the array has 3 components,
> vtk_to_numpy returns an array of shape (10,3). This makes the
> following impossible
>
> vtk_to_numpy(scalar) + vtk_to_numpy(vector)
Try this:
vtk_to_numpy(scalar)[:,None] + vtk_to_numpy(vector)
This is the way to broadcast the 1D array so the addition is possible.
> Shouldn't vtk_to_numpy return an array of shape (10,1) when converting scalars?
Not really since a (10,1) array is like a column vector. If you did
x = linspace(0, 10)
you end up with an array with shape (50,) and not (50,1) so it seems
more natural to return a 1 component array with 10 elements as a (10,)
shape array.
> Happy new year!
Thanks! Wishing you the same!
cheers,
prabhu
More information about the vtk-developers
mailing list