Skip to content

Basic example from readme not working #299

Open

Description

@jherkenhoff

When trying to execute the example shown in the readme, I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[5], [line 61](vscode-notebook-cell:?execution_count=5&line=61)
     58 import matplotlib.pyplot as plt
     59 import matplotlib.tri as tri
---> 61 triang = tri.Triangulation(verts[:,0], verts[:,1])
     63 fig, ax = plt.subplots()
     64 ax.set_aspect('equal')

TypeError: tuple indices must be integers or slices, not tuple

My versions:

  • Python: 3.12.3
  • PyMFEM: 4.8.0.1
  • Matplotlib: 3.10.1

Activity

  1. jherkenhoff commented on Oct 23, 2025

    @jherkenhoff
    Author

    The problem: mesh.GetVertexArray() returns a tuple of 1D numpy arrays instead of a 2D numpy array. Thats why slicing [:, 0] does not work.

    The example runs when replacing verts = mesh.GetVertexArray() with verts = np.array(mesh.GetVertexArray()). However, I think this should be considered only a hotfix, because the documentation states that it should return a 2D numpy array.

  2. jherkenhoff commented on Oct 23, 2025

    @jherkenhoff
    Author

    Duplicate of #178

  3. sshiraiwa commented on Oct 28, 2025

    @sshiraiwa
    Member

    @jherkenhoff Thank you for reminding this. I think the reason behind this is that the vertices data
    is not simple contiguous array data in MFEM, and it is nice to return an numpy array as a view to
    the original data (thus you can modify it if you need.). I will update the doc and example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions