# Creating a field from a numpy array

**URL:** https://discourse.paraview.org/t/creating-a-field-from-a-numpy-array/15255
**Category:** ParaView Support
**Tags:** python, vtk
**Created:** [August 19, 2024, 3:28pm UTC](https://discourse.paraview.org/t/creating-a-field-from-a-numpy-array/15255 "2024-08-19T15:28:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![aszaboa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/aszaboa/32/15041_2.png) [@aszaboa](https://discourse.paraview.org/u/aszaboa)
#### Post date: [August 19, 2024, 3:28pm UTC](https://discourse.paraview.org/t/creating-a-field-from-a-numpy-array/15255/1 "2024-08-19T15:28:35Z")

</div>

I am working with pvpython (paraview version 5.9). I have a calculator object, obtained from a slice. What I want to do is export the array corresponding to the velocity field, then manipulate it, load back the modified numpy array with a new name to do additional calculations (calculate the mean value).

The exporting of the array works fine with

```auto
dat = dsa.WrapDataObject(sm.Fetch(calculator9))
numpy_array = numpy_support.vtk_to_numpy(dat.PointData["Velocity"])

```

However, I am not sure how to create a new field in `calculator9`. I can add the numpy vectors to the `dat` object with `dat.PointData.AddArray()`, but this does not affect the `calculator9` object.

Any help is appreciated!

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [August 19, 2024, 4:15pm UTC](https://discourse.paraview.org/t/creating-a-field-from-a-numpy-array/15255/2 "2024-08-19T16:15:06Z")

</div>

Usually, you do not want to `Fetch` data in ParaView, as it does not integrate well into the pipeline architecture.

If you want to manipulate a data array in python, please use the `Python Calculator` filter (for one liner expressions) or the `Programmable Filter` for advanced use.

[https://docs.paraview.org/en/latest/UsersGuide/filteringData.html#python-calculator](https://docs.paraview.org/en/latest/UsersGuide/filteringData.html#python-calculator)

[https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html](https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html)

---

<div class="post-metadata">

### Author: ![aszaboa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/aszaboa/32/15041_2.png) [@aszaboa](https://discourse.paraview.org/u/aszaboa)
#### Post date: [August 19, 2024, 5:35pm UTC](https://discourse.paraview.org/t/creating-a-field-from-a-numpy-array/15255/3 "2024-08-19T17:35:41Z")

</div>

Thanks for the prompt reply, that is very helpful. What I still do not understand is how can one specify multiple inputs to a filter. There are examples that show how multiple inputs work inside the `ProgrammableFilter.Script`, but I am unsure how to initialize the filter with multiple inputs.

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [August 20, 2024, 6:51am UTC](https://discourse.paraview.org/t/creating-a-field-from-a-numpy-array/15255/4 "2024-08-20T06:51:02Z")

</div>

A filter has a `Input` attribute that can be either another filter (the `ActiveSource` if not specified) or a _list of filters_.

Some more infos: [5. Filtering Data — ParaView Documentation 5.12.0 documentation](https://docs.paraview.org/en/latest/UsersGuide/filteringData.html#id1)

---

<div class="post-metadata">

### Author: ![aszaboa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/aszaboa/32/15041_2.png) [@aszaboa](https://discourse.paraview.org/u/aszaboa)
#### Post date: [August 21, 2024, 10:29am UTC](https://discourse.paraview.org/t/creating-a-field-from-a-numpy-array/15255/5 "2024-08-21T10:29:49Z")

</div>

Thanks for the clarification. I managed to figure out that if I want to pass additonal arguments to a filter, I need to define a class like [here](https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html#python-algorithm). However, I am struggling to find any complete examples how can I use the filter class inside a pvpython script.

Once again, what I want to do create a new filter from another one. In the output filter, there is an additional field, which is created through assigning the `PointData`. Actually very much like in the first example of the page I linked, and I think I got the general idea, but there are still parts of the picture missing as I am not very familiar with paraview scripting.
