# Programmable Filter: if else statment

**URL:** https://discourse.paraview.org/t/programmable-filter-if-else-statment/7514
**Category:** ParaView Support
**Created:** [June 29, 2021, 7:39pm UTC](https://discourse.paraview.org/t/programmable-filter-if-else-statment/7514 "2021-06-29T19:39:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![CSMDakota](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/3d9bf3/32.png) [@CSMDakota](https://discourse.paraview.org/u/CSMDakota)
#### Post date: [June 29, 2021, 7:39pm UTC](https://discourse.paraview.org/t/programmable-filter-if-else-statment/7514/1 "2021-06-29T19:39:11Z")

</div>

I’m trying to implement at programmable filter in which I read in an existing array from an imported solution, then calculate a new array based on an “if” “else” statement. Specifically if a nodal value is greater than zero, I perform a different calculation than if it is negative.

I’m stuck where the code is trying to evaluate the data in the existing array against “\>= 0”. I think it may have to do with the fact that the data type is a ‘VTKCompositeDataArray’ and I’m trying to compare it to an integer or float. The snippet below always evaluates \>=0 at TRUE even though there are negative values in the solution.

Is there a way I should convert the conditional statement parameters to the same data type, or another/better way to fix this issue? I can’t quite find a solution after searching through the various examples online.

Thanks!  
Brandon  
Windows, Paraview v5.9.1

```auto
import numpy as np
input0 = inputs[0]

# Max principle stress midpoint value array
Sigma_m = input0.PointData["Stress_maxPrin_Mid"]

# Constants
numPoints = input0.GetNumberOfPoints()
Ct = 1.0
Sut = 1.474*10**9

# New array for output
pointArray = np.empty(numPoints,dtype=np.float64)

# Iterate through Sigma_m array, populate pointArray according to if/else statement
for i in range(numPoints):
    # the next line is giving the troubles, I believe
    if Sigma_m[i] >= 0:  
        pointArray[i] = (Ct*Sut*input0.PointData["Stress_maxPrin_Alt"])/(Ct*Sut-input0.PointData["Stress_maxPrin_Mid"])
      
    else:
        pointArray[i] = input0.PointData["Stress_maxPrin_Alt"]
        
  output.PointData.append(pointArray,"Stress_maxPrin_r")

```

---

<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: [June 30, 2021, 7:25am UTC](https://discourse.paraview.org/t/programmable-filter-if-else-statment/7514/2 "2021-06-30T07:25:08Z")

</div>

> [@Operations on multi-block dataset with Programmable Filter](https://discourse.paraview.org/t/operations-on-multi-block-dataset-with-programmable-filter/1027/6):
>
> Ah, indeed. The usual numpy functions do not work for VTKCompositeDataArrays that are available from multiblock datasets, but the numpy-like algorithms provided by vtk.numpy\_interface.algorithms do. However, the where function provided in vtk.numpy\_interface.algorithms is only the single-argument version, not the three-argument version I suggested, so merging the blocks is the only way to use this numpy expression currently.

---

<div class="post-metadata">

### Author: ![CSMDakota](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/3d9bf3/32.png) [@CSMDakota](https://discourse.paraview.org/u/CSMDakota)
#### Post date: [July 12, 2021, 9:30pm UTC](https://discourse.paraview.org/t/programmable-filter-if-else-statment/7514/3 "2021-07-12T21:30:39Z")

</div>

Thanks, Mathieu, for this link; I hadn’t seen that post. Indeed, passing the data first through a Merge Blocks filter then allows either the simple Python Calculator “np.where()” to work as Cory suggested, or the Programmable Filter above works now as well.

Thanks again, all!  
–Brandon–
