# Python Annotation - Variable for Velocity Magnitude and x,y,z direction

**URL:** https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836
**Category:** ParaView Support
**Created:** [October 24, 2019, 5:38pm UTC](https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836 "2019-10-24T17:38:01Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Schneider](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Schneider](https://discourse.paraview.org/u/Schneider)
#### Post date: [October 24, 2019, 5:38pm UTC](https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836/1 "2019-10-24T17:38:01Z")

</div>

I like to measure the mean velocity (magnitude and x,y and z direction) with a python annotation.

What is the right variable for it ? I tried  
`mean(U(inputs[0]))` for the magnitude  
`mean(Velocity(inputs[0]))` for the magnitude  
`mean(Ux(inputs[0]))` in x direction  
`mean(U_x(inputs[0]))` in x direction  
`mean(Velocityx(inputs[0]))` in x direction  
`mean(Velocity_x(inputs[0]))` in x direction  
nothing works out.

What is the right variable for the velocity magnitude and in the directions ?

Cheers  
Schneider

---

<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: [October 25, 2019, 6:40am UTC](https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836/2 "2019-10-25T06:40:49Z")

</div>

The right formula would depends on the name of your arrays.  
Alternatively, you can use descriptive statistics filter.

---

<div class="post-metadata">

### Author: ![Schneider](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Schneider](https://discourse.paraview.org/u/Schneider)
#### Post date: [October 29, 2019, 6:09pm UTC](https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836/3 "2019-10-29T18:09:19Z")

</div>

Ok,  
is there a predefined variable for the velocity in x, y, z direction and the magnitude ?

I can display the mean velocity, i used the code

```
mean(U)

```

this ist the (Ux+Uy+Uz)/3.

---

<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: [October 30, 2019, 12:52pm UTC](https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836/4 "2019-10-30T12:52:41Z")

</div>

Not sure to follow what is your question.

If “U” is your vector, the U\_X, U\_Y, U\_Z are the directional scalars and mag(U) the magnitude.

---

<div class="post-metadata">

### Author: ![Schneider](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@Schneider](https://discourse.paraview.org/u/Schneider)
#### Post date: [October 31, 2019, 8:35am UTC](https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836/5 "2019-10-31T08:35:06Z")

</div>

Thank you very much Mathieu Westphal !

Now, its getting clearer to me.

In example i got an array `U = [7, 3, -4; 5, -2, 9; 1, 6 , 4]`

The Ux component is [7, 5, 1], the Uy component [3, -2, 6] and Uz [-4, 9, 4]  
So i tried to isolate the Ux components with `mean((U) * (1,0,0)` this will change the U array to

`U = [7, 0, 0; 5, 0, 0; 1, 0 , 0]`

The mean U value is (7+0+0+5+0+0+1+0+0) / 9 and this is not what i want.  
Is has to be (7+5+1) / 3.

So i search for a way to extract the Ux, y and z components into a vector and get the mean value out of it.

---

<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: [October 31, 2019, 8:38am UTC](https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836/6 "2019-10-31T08:38:46Z")

</div>

To be honest, this is more a python question than a ParaView question here.

what about `mean(U_X)` ?

---

<div class="post-metadata">

### Author: ![Kai\_himself](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kai_himself/32/280_2.png) [@Kai\_himself](https://discourse.paraview.org/u/Kai_himself)
#### Post date: [October 31, 2019, 3:04pm UTC](https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836/7 "2019-10-31T15:04:58Z")

</div>

yes it is, you are right.

Its for U\_x mean(U[:,0]).  
[https://www.python-kurs.eu/numpy\_arrays\_erzeugen.php](https://www.python-kurs.eu/numpy_arrays_erzeugen.php)

: for all rows and 0 for the first column like x.

best regards  
kai

---

<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: [May 7, 2024, 7:33am UTC](https://discourse.paraview.org/t/python-annotation-variable-for-velocity-magnitude-and-x-y-z-direction/2836/8 "2024-05-07T07:33:00Z")

</div>

A post was split to a new topic: [Compute velocity](https://discourse.paraview.org/t/compute-velocity/14568)
