# How to calculate the average volume of each Voronoi polyhedra type?

Dear Ovito developers,

I am trying to calculate the most frequent polyhedra using the OVITO script:

https://www.ovito.org/docs/current/python/introduction/examples/batch_scripts/voronoi_indices.php

This helps me calculating the most frequent indices easily, but I also want to calculate the average volume of each frequent index or each polyhedra type.

Thank you.

Hi Kingsley,

You can find the indices of atoms with a specific Voronoi Index (in this example the most frequent one) like this,

`numpy.where((voro_indices == unique_indices).all(axis=1))`

that means you can look up their corresponding Voronoi volumes like this:

```voro_volumes = data.particles["Atomic Volume"]
voro_volumes[numpy.where((voro_indices == unique_indices).all(axis=1))])]```

and simply use `numpy.mean()`to calculate the average value:

`numpy.mean(voro_volumes[numpy.where((voro_indices == unique_indices).all(axis=1))])`

Dear Constanze,

Thank you very much for your tip. But I got some errors here.

I want to calculate 500 frame data and save all results of each frame into a file. But it has some errors in getting the average polyhedra volume of every index or something. Could you please have a look?

Thank you.

```...
...

out1=open("CuZr.txt",'a')
for frame in range(pipeline.source.num_frames):
data = pipeline.compute(frame)
voro_indices = data.particles["Voronoi Index"]
unique_indices, counts = row_histogram(voro_indices)

# Find the average volume of every index
voro_volumes = data.particles["Atomic Volume"]
avol = numpy.empty(, dtype=float)
for v in range(20):
vol = voro_volumes[numpy.where((voro_indices == unique_indices[v]).all(axis=1))]
avols = numpy.mean(voro_volumes[numpy.where((voro_indices == unique_indices[v]).all(axis=1))])

for i in range(20):
print("%s\t= %i\t\t%.2f %%\t%.2f" % (tuple(unique_indices[i][2:]),counts[i],100.0*float(counts[i])/len(voro_indices),avol[i]),file=out1)
out1.close()
```

In your code snippet, `avol` is an empty numpy array of shape `(20,)`, so using it in your print statement in line 56 doesn't make much sense. 