# how to get average or mean of a block

**URL:** https://discourse.paraview.org/t/how-to-get-average-or-mean-of-a-block/1396
**Category:** ParaView Support
**Created:** [March 5, 2019, 8:16pm UTC](https://discourse.paraview.org/t/how-to-get-average-or-mean-of-a-block/1396 "2019-03-05T20:16:14Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![wascott](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/8e8cbc/32.png) [@wascott](https://discourse.paraview.org/u/wascott)
#### Post date: [March 5, 2019, 8:16pm UTC](https://discourse.paraview.org/t/how-to-get-average-or-mean-of-a-block/1396/1 "2019-03-05T20:16:14Z")

</div>

I have a user that would like to find the average or mean of a variable over a block. This is on a large dataset, and only loads into ParaView on a cluster. Thus, I need a parallel solution. This is on a multiblock dataset.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [March 5, 2019, 8:23pm UTC](https://discourse.paraview.org/t/how-to-get-average-or-mean-of-a-block/1396/2 "2019-03-05T20:23:58Z")

</div>

You should be able to use **Python Annotation** and an expression like `mean(arrayName.Arrays[blockId])` where `arrayName` is the name of the array and `blockId` is the block ID. Make sure to set the _Array Association_ appropriately to make the array names available as variables in the Python expression, e.g., “Point Data” or “Cell Data”.

---

<div class="post-metadata">

### Author: ![wascott](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/8e8cbc/32.png) [@wascott](https://discourse.paraview.org/u/wascott)
#### Post date: [March 6, 2019, 1:12am UTC](https://discourse.paraview.org/t/how-to-get-average-or-mean-of-a-block/1396/3 "2019-03-06T01:12:38Z")

</div>

Thanks Cory! Won’t this double count Points between processor boundaries? I assume ghost cells won’t help here either?

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [March 6, 2019, 6:54pm UTC](https://discourse.paraview.org/t/how-to-get-average-or-mean-of-a-block/1396/4 "2019-03-06T18:54:04Z")

</div>

Unfortunately, it will indeed double count points/cells duplicated across ranks.

If you are finding the mean of **cell** data and have ghost cells, you should be able to apply **Remove Ghost Information** to avoid double counting cells.

---

<div class="post-metadata">

### Author: ![wascott](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/8e8cbc/32.png) [@wascott](https://discourse.paraview.org/u/wascott)
#### Post date: [March 7, 2019, 8:04pm UTC](https://discourse.paraview.org/t/how-to-get-average-or-mean-of-a-block/1396/5 "2019-03-07T20:04:16Z")

</div>

@cory.quammen I tried what you said, and it didn’t work. Here is what I did:

- 5.6.0, Linux, builtin server.
- Open can.exo. All variables on. Apply.
- (Check with the spreadsheet which blocks are which. Currently, blocks are named 2 and 3. Grrr).
- Python Annotation. Expression is mean(ACCL.Arrays[2]). Apply.  
Error message is name ‘ACCL’ is not defined.

What are my user and I doing wrong?

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [March 7, 2019, 8:25pm UTC](https://discourse.paraview.org/t/how-to-get-average-or-mean-of-a-block/1396/6 "2019-03-07T20:25:37Z")

</div>

Make sure that the _Array Association_ is set to “Point Data”.

As for the array index, admittedly this will be an unsatisfying answer, but the `blockIdx` in `Arrays[blockIdx]` is the _linear index_ of the leaf datasets in the block structure if you perform an in-order traversal of the multiblock data structure, not the number in the spreadsheet or the _Find Data_ dialog. For can.exo, there are two blocks index 0 and 1. This is not an ideal way to address blocks in a Python expression, but its what we have available.

Probably a better thing to do is add an **Extract Block** filter to extract the block you want to find the mean of followed by a **Python Annotation** with the expression `mean(ACCL)`. That saves you the trouble of figuring out the array index from the block structure.
