# Converting mesh data to and from numpy array

Hello,

I’ve put my vertex data into a numpy array and done some operations on it. Is there a built in helper function to get the numpy array back into the mesh’s vertex data? thanks

``````import bpy
import mathutils
import numpy as np
import bmesh

mesh_object = bpy.context.active_object

# Ensure it's a mesh
if mesh_object and mesh_object.type == 'MESH':
mesh = mesh_object.data

#bm = bmesh.new()
#bm.from_mesh(mesh)

# Extract vertex coordinates as NumPy array
positions = np.array([v.co for v in mesh.vertices])

# Extract edges as NumPy array
edges = np.array([(edge.vertices[0], edge.vertices[1]) for edge in mesh.edges])

# Now you have vertices and edges as NumPy arrays
print("Vertices:")
print(positions)
print("\nEdges:")
print(edges)
else:
print("Please select a valid mesh object.")

# Initialise timestep (seconds), vertex weight (kg), gravity
timestep = 0.2
weight = 0.05
gravity = np.array([0,0,-9.8])
print(gravity)

#initialise velocities
velocities = np.zeros_like(positions)
print(velocities)

for i in range(0, 8):
velocities+= timestep*weight*gravity
positions += timestep*velocities

print(positions)

#TODO: update mesh with new positions
``````

For anyone else interested i found the answer here
https://blog.michelanders.nl/2016/02/copying-vertices-to-numpy-arrays-in_4.html