# Vector operations in Python Calculator

**URL:** https://discourse.paraview.org/t/vector-operations-in-python-calculator/17217
**Category:** ParaView Support
**Created:** [September 27, 2025, 3:25pm UTC](https://discourse.paraview.org/t/vector-operations-in-python-calculator/17217 "2025-09-27T15:25:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Captain\_Convergence](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@Captain\_Convergence](https://discourse.paraview.org/u/Captain_Convergence)
#### Post date: [September 27, 2025, 3:25pm UTC](https://discourse.paraview.org/t/vector-operations-in-python-calculator/17217/1 "2025-09-27T15:25:29Z")

</div>

Dear support,

I am struggling to perform some basic operations to get the moments around an axis. My objective is to find the normal force around an axis following this sketch:

 ![image](https://discourse.paraview.org/uploads/default/original/3X/0/2/02e1635ed551055826f4cb75ccf4366419fdfbd9.png)

Where AB is the axis that I’ve defined using a line filter and P is the point where a vector force is stored in my dataset.

The first step is to get the AP vector which works fine using this python calculator:

```auto
# Get reference to the inputs
surf = inputs[0]
axis = inputs[1]

# Get axis vector
A = axis.Points[0,:]
B = axis.Points[-1,:]
AB = B-A # VTKArray - Shape(3,)
AB = AB.reshape((3, 1))

# AP vector
AP = surf.Points-A # VTKCompositeDataArray - Shape(35248, 3)

return AP

```

And there you have the magnitude of the AP vector which increases as you get away from A

 ![image](https://discourse.paraview.org/uploads/default/original/3X/4/a/4ab0dac641f0aed782bb24043d952f1dcc06ff42.jpeg)

But then I need to perform dot and cross operations between the AB and AP vectors I the following code crashes:

```auto
# Get reference to the inputs
surf = inputs[0]
axis = inputs[1]

# Get axis vector
A = axis.Points[0,:]
B = axis.Points[-1,:]
AB = B-A # VTKArray - Shape(3,)
AB = AB.reshape((3, 1))

# AP vector
AP = surf.Points-A # VTKCompositeDataArray - Shape(35248, 3)

return cross(AB,AP)

```

Is it possible to get the cross and dot product of 2 vectors which belong to different filters in a simple way? I know how to do this using the regular calculators but I am trying to do this in a python calculator to simplify a bit my pipeline 😉

Thank you in advance for your time!

---

<div class="post-metadata">

### Author: ![Captain\_Convergence](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@Captain\_Convergence](https://discourse.paraview.org/u/Captain_Convergence)
#### Post date: [September 28, 2025, 4:41pm UTC](https://discourse.paraview.org/t/vector-operations-in-python-calculator/17217/2 "2025-09-28T16:41:14Z")

</div>

I’ve found a way to bypass this issue (after MANY tries) but I am a bit clueless of why this is the only solution that I could find so far:

```auto
import numpy as np

# Get reference to the inputs
surf = inputs[0]
axis = inputs[1]

# Get axis vector
A = axis.Points[0,:]
B = axis.Points[-1,:]
AB = B-A # VTKArray - Shape(3,)

# AP vector
AP = surf.Points-A # VTKCompositeDataArray - Shape(N Pts, 3)

# Bypass: Using an existing VTKCompositeDataArray, 
# set it to 0 and sum your desired vector
AB_arr = AP * 0 + [AB[0], AB[1], AB[2]]

return cross(AP,AB_arr)

```

Also I’ve found another issue when using the “norm“ command to normalize the array that I had to bypass in a similar way. Instead of doing this:

```auto
n = norm(cross(AB_arr,r))

```

I have to do this:

```auto
# Bypass: Using an existing VTKCompositeDataArray, 
# set it to 0 and sum your desired vector
Ones4dot_arr = AP * 0 + [1, 1, 1]

# Moment vector direction (n).
n = cross(AB_arr,r) / dot(Ones4dot_arr,Ones4dot_arr)
n = norm(n)

```

Is there any better/elegant way to perform these operations?

---

<div class="post-metadata">

### Author: ![Captain\_Convergence](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@Captain\_Convergence](https://discourse.paraview.org/u/Captain_Convergence)
#### Post date: [September 30, 2025, 5:44pm UTC](https://discourse.paraview.org/t/vector-operations-in-python-calculator/17217/3 "2025-09-30T17:44:11Z")

</div>

It would be very convenient to know how to declare new VTKArrays or VTKCompositeDataArrays inside the python calculator in an efficient manner to understand the structure of the data but I couldn’t find answers online 😃

---

<div class="post-metadata">

### Author: ![Captain\_Convergence](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@Captain\_Convergence](https://discourse.paraview.org/u/Captain_Convergence)
#### Post date: [November 5, 2025, 4:22pm UTC](https://discourse.paraview.org/t/vector-operations-in-python-calculator/17217/4 "2025-11-05T16:22:01Z")

</div>

No thoughts on any of this? 🙁
