amep.utils.mesh_to_coords#

amep.utils.mesh_to_coords(X: ndarray, Y: ndarray) ndarray#

Converts positions in two-dimensional space given as a meshgrid into an array of two-dimensional position vectors of shape (N,2), where N is the total number of positions in the given meshgrid.

Parameters:
  • X (np.ndarray) – Two-dimensional array of x positions on a grid in form of a meshgrid.

  • Y (np.ndarray) – Two-dimensional array of y positions on a grid in form of a meshgrid.

Returns:

Array of shape (N,2) containing the position vector of each grid point.

Return type:

np.ndarray

Examples

>>> import amep
>>> import numpy as np
>>> x = np.linspace(-1,1,3)
>>> y = np.linspace(-2,2,5)
>>> X,Y = np.meshgrid(x,y)
>>> print(X)
[[-1.  0.  1.]
 [-1.  0.  1.]
 [-1.  0.  1.]
 [-1.  0.  1.]
 [-1.  0.  1.]]
>>> print(Y)
[[-2. -2. -2.]
 [-1. -1. -1.]
 [ 0.  0.  0.]
 [ 1.  1.  1.]
 [ 2.  2.  2.]]
>>> print(amep.utils.mesh_to_coords(X,Y))
[[-1. -2.]
 [ 0. -2.]
 [ 1. -2.]
 [-1. -1.]
 [ 0. -1.]
 [ 1. -1.]
 [-1.  0.]
 [ 0.  0.]
 [ 1.  0.]
 [-1.  1.]
 [ 0.  1.]
 [ 1.  1.]
 [-1.  2.]
 [ 0.  2.]
 [ 1.  2.]]
>>>