# Create tensor from vectors

**URL:** https://discourse.paraview.org/t/create-tensor-from-vectors/7761
**Category:** ParaView Support
**Tags:** exodus, python
**Created:** [August 4, 2021, 10:20am UTC](https://discourse.paraview.org/t/create-tensor-from-vectors/7761 "2021-08-04T10:20:09Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![YYang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/y/a9adbd/32.png) [@YYang](https://discourse.paraview.org/u/YYang)
#### Post date: [August 4, 2021, 10:20am UTC](https://discourse.paraview.org/t/create-tensor-from-vectors/7761/1 "2021-08-04T10:20:09Z")

</div>

Dear paraview staffs  
I am recently doing visualization of the anisotropy of the local conductivity on an FEM output (in exodus), in which the conductivity is separately saved as three vector fields k\_x, k\_y and k\_z. As suggested by the [wiki](https://www.paraview.org/Wiki/Python_calculator_and_programmable_filter), I am using the following lines in the program filter

```auto
from paraview.vtk.numpy_interface import dataset_adapter as dsa
import numpy

def make_tensor(xx,yy,zz, xy, yz, xz):
	t = numpy.vstack([xx,yy,zz,xy, yz, xz]).transpose().view(dsa.VTKArray)
	t.DataSet = xx.DataSet
	t.Association = xx.Association
	return t

xx = inputs[0].PointData["k_x"][:,0]
yy = inputs[0].PointData["k_y"][:,1]
zz = inputs[0].PointData["k_z"][:,2]
xy = inputs[0].PointData["k_x"][:,1]
yz = inputs[0].PointData["k_y"][:,2]
xz = inputs[0].PointData["k_z"][:,0]

output.PointData.append(make_tensor(xx,yy,zz,xy,yz,xz), "tensor")

```

yet paraview keeps returning the error “TypeError: Could not find a suitable VTK type for object”.

Btw, I also tried to separate the components of the conductivity as scalar fields k\_11, k\_22, k\_33, k\_12, k\_23, k\_13, and use the original code provided by the wiki, still obtained the same error msg.

Could someone please explain how to fix the error? Thank you in advance  
Best  
Yang

---

<div class="post-metadata">

### Author: ![YYang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/y/a9adbd/32.png) [@YYang](https://discourse.paraview.org/u/YYang)
#### Post date: [August 4, 2021, 4:51pm UTC](https://discourse.paraview.org/t/create-tensor-from-vectors/7761/2 "2021-08-04T16:51:11Z")

</div>

I am not so sure, but the following code works

```auto
from paraview.vtk.numpy_interface import dataset_adapter as dsa
import numpy

def make_tensor(xx,yy,zz,xy,yz,xz):
 t = numpy.vstack([xx.Arrays[0],yy.Arrays[0],zz.Arrays[0],xy.Arrays[0],yz.Arrays[0],xz.Arrays[0]]).transpose().view(dsa.VTKArray)
 t.DataSet = xx.DataSet
 t.Association = xx.Association
 return t

xx = inputs[0].PointData["k_x"][:,0]
yy = inputs[0].PointData["k_y"][:,1]
zz = inputs[0].PointData["k_z"][:,2]
xy = inputs[0].PointData["k_x"][:,1]
yz = inputs[0].PointData["k_y"][:,2]
xz = inputs[0].PointData["k_z"][:,0]

output.PointData.append(make_tensor(xx,yy,zz,xy,yz,xz), "tensor")

```

which creates a new PointData ‘tensor’ with components as XX, YY, ZZ, XY, YZ, XZ . TensorGlyph filter is also activated then.  
I would then continue trying with the TensorGlyph and would be back to this question. Please point out if there is any possible mistakes.

Best  
Yang
