# numpy/scipy to aster datas, and vice versa

**URL:** <https://code-aster.org/forum/t/numpy-scipy-to-aster-datas-and-vice-versa/12300>\
**Category:** Code\_Aster usage\
**Created:** [June 25, 2026, 2:28pm UTC](https://code-aster.org/forum/t/numpy-scipy-to-aster-datas-and-vice-versa/12300 "2026-06-25T14:28:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinr](https://code-aster.org/forum/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@martinr](https://code-aster.org/forum/u/martinr)\
**Post date:** [June 25, 2026, 2:28pm UTC](https://code-aster.org/forum/t/numpy-scipy-to-aster-datas-and-vice-versa/12300/1 "2026-06-25T14:28:04Z")

</div>

Hi,

is it possible to create `cham_no` type of data from a numpy array ?

Is it possible to do the same for matrices, create one from sparse datas ? (Because of element dependancy, I primarly think no, but why not.)

If not, how to add rows and columns to an existing aster matrix ? Add rows to an existing aster vector ?

The idea is to solve a linear problem with large amount of dofs. It would be better to do it inside aster rather than scipy I think.

---

<div class="post-metadata">

**Author:** ![martinr](https://code-aster.org/forum/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@martinr](https://code-aster.org/forum/u/martinr)\
**Post date:** [June 26, 2026, 12:29pm UTC](https://code-aster.org/forum/t/numpy-scipy-to-aster-datas-and-vice-versa/12300/2 "2026-06-26T12:29:59Z")

</div>

I dig a bit in the subject.

I am able to modify an existing `cham_no` like

```auto
PHI = CREA_CHAMP(NOM_CHAM='DEPL',
                 NUME_MODE=1,
                 OPERATION='EXTR',
                 RESULTAT=modes,
                 TYPE_CHAM='NOEU_DEPL_R')

PHI2 = PHI
PHI2.setValues(list_of_vals)

```

How to create one from nothing ?

In the help of [libaster](https://codeaster.readthedocs.io/en/latest/_modules/libaster.html) there is the initialisation of `FieldOnNodesReal`

```auto
def __init__ (self, *args, **kwargs):
        """Overloaded function.

        1. __init__ (self: libaster.FieldOnNodesReal) -> None

        2. __init__ (self: libaster.FieldOnNodesReal, arg0: libaster.FieldOnNodesReal) -> None

        3. __init__ (self: libaster.FieldOnNodesReal, arg0: Model) -> None

        4. __init__ (self: libaster.FieldOnNodesReal, arg0: libaster.BaseDOFNumbering) -> None

        5. __init__ (self: libaster.FieldOnNodesReal, arg0: libaster.EquationNumbering) -> None

        6. __init__ (self: libaster.FieldOnNodesReal, arg0: tuple) -> None

        7. __init__ (self: libaster.FieldOnNodesReal, mesh: libaster.BaseMesh, quantity: str, cmps: list[str]) -> None

        8. __init__ (self: libaster.FieldOnNodesReal, mesh: libaster.BaseMesh, quantity: str, values: dict[str, float], groupsOfNodes: list[str] = [], groupsOfCells: list[str] = []) -> None
        """

```

I don’t know what are the lasts inputs in 7 and 8 (mesh is ok I think, from `LIRE_MAILLAGE`).

Anyone ?

---

<div class="post-metadata">

**Author:** ![martinr](https://code-aster.org/forum/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@martinr](https://code-aster.org/forum/u/martinr)\
**Post date:** [June 26, 2026, 1:40pm UTC](https://code-aster.org/forum/t/numpy-scipy-to-aster-datas-and-vice-versa/12300/3 "2026-06-26T13:40:18Z")

</div>

The 8th options seems the most adapted but I don’t know how to fill it.

I do

```auto
import code_aster
A = code_aster.Objects.FieldOnNodesReal(mesh, 'DEPL_R')

```

but I don’t know how to build the dict asked. The str is the componant, so I would say ‘DX’, ‘DY’ and ‘DZ’, but you cannot have repeated keys in the dict so i don’t know how to do this…

---

<div class="post-metadata">

**Author:** ![martinr](https://code-aster.org/forum/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@martinr](https://code-aster.org/forum/u/martinr)\
**Post date:** [June 26, 2026, 2:15pm UTC](https://code-aster.org/forum/t/numpy-scipy-to-aster-datas-and-vice-versa/12300/4 "2026-06-26T14:15:07Z")

</div>

With the 7. :

```auto
import numpy as np
import code_aster
A = code_aster.Objects.FieldOnNodesReal(mesh, 'DEPL_R', ['DX', 'DY', 'DZ'])
A.setValues(phi.tolist())

```
