# Making a tensor from scalars

**URL:** https://discourse.paraview.org/t/making-a-tensor-from-scalars/2914
**Category:** ParaView Support
**Tags:** python
**Created:** [November 5, 2019, 4:39pm UTC](https://discourse.paraview.org/t/making-a-tensor-from-scalars/2914 "2019-11-05T16:39:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Mike](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.paraview.org/u/Mike)
#### Post date: [November 5, 2019, 4:39pm UTC](https://discourse.paraview.org/t/making-a-tensor-from-scalars/2914/1 "2019-11-05T16:39:40Z")

</div>

Dear ParaView Community,

I have the components of a tensor as scalar variables, and I would like to combine them into a single tensor variable so I can use the Tensor Glyph filter. The ParaView [Wiki](https://www.paraview.org/Wiki/Python_calculator_and_programmable_filter) indicates that this can be done using a Programmable Filter, but when I use the suggested script, I get the following error: “TypeError: Could not find a suitable VTK type for object.” Could someone please explain how to fix the error? Here is the script from the Wiki:

```
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["sigma_xx"]
yy = inputs[0].PointData["sigma_yy"]
zz = inputs[0].PointData["sigma_zz"]
xy = inputs[0].PointData["sigma_xy"]
yz = inputs[0].PointData["sigma_yz"]
xz = inputs[0].PointData["sigma_xz"]
output.PointData.append(make_tensor(xx,yy,zz,xy,yz,xz), "tensor")

```

Best regards,  
Mike

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [November 7, 2019, 9:28am UTC](https://discourse.paraview.org/t/making-a-tensor-from-scalars/2914/2 "2019-11-07T09:28:23Z")

</div>

Can you share your input data ?

You need to make sure that your data contains `sigma_xx` and other arrays.

---

<div class="post-metadata">

### Author: ![lvelt](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/l/8491ac/32.png) [@lvelt](https://discourse.paraview.org/u/lvelt)
#### Post date: [September 27, 2021, 2:08pm UTC](https://discourse.paraview.org/t/making-a-tensor-from-scalars/2914/3 "2021-09-27T14:08:32Z")

</div>

Hello,

I have the same problem as Mike described. Using

> output.PointData.append(xx, “test”)

is working so I am sure that the data is called successfully. However, I am not able to create a tensor using the function from the Wiki.

Best Regards

Lennart

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 28, 2021, 2:16pm UTC](https://discourse.paraview.org/t/making-a-tensor-from-scalars/2914/6 "2021-09-28T14:16:35Z")

</div>



---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 28, 2021, 2:16pm UTC](https://discourse.paraview.org/t/making-a-tensor-from-scalars/2914/7 "2021-09-28T14:16:52Z")

</div>

Can you share the code that is not working in your case ?

---

<div class="post-metadata">

### Author: ![mckel](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mckel/32/6435_2.png) [@mckel](https://discourse.paraview.org/u/mckel)
#### Post date: [February 10, 2022, 9:16am UTC](https://discourse.paraview.org/t/making-a-tensor-from-scalars/2914/8 "2022-02-10T09:16:53Z")

</div>

I had the same issue as Lennart. Figured out it was related to the input data being a `vtkMultiBlockDataSet`. Adding a `MergeBlocks` filter helped.
