# Issue with programmable filter in ParaView 5.9

**URL:** https://discourse.paraview.org/t/issue-with-programmable-filter-in-paraview-5-9/6249
**Category:** ParaView Support
**Created:** [January 18, 2021, 5:47am UTC](https://discourse.paraview.org/t/issue-with-programmable-filter-in-paraview-5-9/6249 "2021-01-18T05:47:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ebreard](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ebreard/32/2421_2.png) [@ebreard](https://discourse.paraview.org/u/ebreard)
#### Post date: [January 18, 2021, 5:47am UTC](https://discourse.paraview.org/t/issue-with-programmable-filter-in-paraview-5-9/6249/1 "2021-01-18T05:47:39Z")

</div>

Hi,

I was running in ParaView 5.9 RC2 this programmable filter which calculates averages of all cells along a given axis, within a defined domain.This works in ParaView 5.5, but not in 5.9:

error 1 : xrange is not defined

error 2 (if i change xrange to range)

Traceback (most recent call last):  
File “”, line 22, in   
File “”, line 24, in RequestData  
TypeError: ‘numpy.float64’ object cannot be interpreted as an integer

programmable filter code:

```python
import numpy as np 
import vtk
 
input=self.GetPolyDataInput()
numPoints =input.GetNumberOfPoints() 
cell_idx_x =np.zeros((numPoints,1),dtype='i') 
cell_idx_y =np.zeros((numPoints,1),dtype='i')
cell_idx_z =np.zeros((numPoints,1),dtype='i')
avg_V=np.zeros((numPoints,1),dtype='f')
cell_size = 0.001
y_min=0.0
z_min=0.0
seuil_epg = 0.001
for i in range(0, numPoints):
    coord =input.GetPoint(i) 
    x, y, z =coord[:3]
    cell_idx_y[i] =((y-y_min)-cell_size/2)/cell_size
    cell_idx_z[i] =((z-z_min)-cell_size/2)/cell_size 
output.PointData.append(cell_idx_y, "idx_Y") 
output.PointData.append(cell_idx_z, "idx_Z")
nb_cell_y=max(cell_idx_y)+1
nb_cell_z=max(cell_idx_z)+1
sum_V=np.zeros((nb_cell_y,nb_cell_z),dtype='f')
nb_vert_cell=np.zeros((nb_cell_y,nb_cell_z),dtype='f')
data =input.GetPointData()
Vel =data.GetArray('V_x')
EPG = data.GetArray('Scalar_2') 
for i in range(0,numPoints):
    phi = EPG.GetValue(i)
    if ( phi > seuil_epg ) :
        V =Vel.GetValue(i)
        nb_vert_cell[cell_idx_y[i],cell_idx_z[i]]=nb_vert_cell[cell_idx_y[i],cell_idx_z[i]]+1
        sum_V[cell_idx_y[i],cell_idx_z[i]]=sum_V[cell_idx_y[i],cell_idx_z[i]]+V
for i in range(0,numPoints):
    if ( sum_V[cell_idx_y[i],cell_idx_z[i]] > 0 ):
        avg_V[i]=sum_V[cell_idx_y[i],cell_idx_z[i]]/nb_vert_cell[cell_idx_y[i],cell_idx_z[i]]
    else:
        avg_V[i]=0
output.PointData.append(avg_V, "avg_V")

```

Could you let me know what should I change to make it work in the new versions of ParaView (5.8 also does not allow this filter to work…)

Thanks a lot for the help!

Eric

---

<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: [January 18, 2021, 9:45am UTC](https://discourse.paraview.org/t/issue-with-programmable-filter-in-paraview-5-9/6249/2 "2021-01-18T09:45:30Z")

</div>

> [@ebreard](#):
>
> error 1 : xrange is not defined

xrange is a Python2 method, we are using Python3 now.

```auto
np.zeros((nb_cell_y,nb_cell_z),dtype='f')

```

This method accepts int accoording to the doc  
[https://numpy.org/doc/stable/reference/generated/numpy.zeros.html](https://numpy.org/doc/stable/reference/generated/numpy.zeros.html)

Unrelated to ParaView.

---

<div class="post-metadata">

### Author: ![ebreard](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ebreard/32/2421_2.png) [@ebreard](https://discourse.paraview.org/u/ebreard)
#### Post date: [January 20, 2021, 11:27pm UTC](https://discourse.paraview.org/t/issue-with-programmable-filter-in-paraview-5-9/6249/3 "2021-01-20T23:27:05Z")

</div>

sum\_V=np.zeros((int(nb\_cell\_y),int(nb\_cell\_z)),dtype=‘f’)

nb\_vert\_cell=np.zeros((int(nb\_cell\_y),int(nb\_cell\_z)),dtype=int)

solved it. Thanks
