# 08 - GridsΒΆ

Grids in AMUSE have a similar functionality as particle sets, but grids are inmutable in the number of grid points in any direction. You cannot add a gridpoint like you add a particle in a particle set, instead you define the number of points in each direction on creation of the grid and amuse will create the grid points.

In[2]:

```from amuse.lab import *
```

Let’s start by creating a simple 3 by 4 grid.

In[3]:

```grid = Grid(3,4)
print grid
```
```Grid (3 x 4)
```

A grid created in this way does not define any positions for the gridpoints, you can make a more useful grid with the create function. The create function needs a list of the number of points in each direction and the total distance covered by the grid in each direction. The created grid will cover the space from 0 to the given total distance in any direction

In[4]:

```grid = Grid.create((3,4),(1|units.m, 2|units.m))
print grid
print grid.x
```
```Grid (3 x 4)
[[ 0.16666667  0.16666667  0.16666667  0.16666667], [ 0.5  0.5  0.5  0.5], [ 0.83333333  0.83333333  0.83333333  0.83333333]] m
```

The returned positions are the centers of the gridpoints, we can make a small plot to show where the grid centers are positioned.

In[10]:

```grid = Grid.create((3,4),(1|units.m, 2|units.m))
scatter(
grid.x.value_in(units.m),
grid.y.value_in(units.m)
)
xlim(0,1)
ylim(0,2)
```
```(0, 2)
```

You can index a grid in two ways, direct indexing on the grid or indexing on an attribute. Direct indexing on a grid can be more efficient as no data is retrieved until you actually requenst an attribute. If you first request an attribute and then do the indexing, all data for the attribute is retrieved and returned first as a vector quantity (or numpy array), next a subselection is made using the indexing routines. Both method should return the same quantities.

In[6]:

```print grid.position[0][0]
print grid[0][0].position
```
```[0.166666666667, 0.25] m
[0.166666666667, 0.25] m
```

Grids can be moved around if needed

In[11]:

```grid.position -= [0.5,1.0] | units.m
scatter(
grid.x.value_in(units.m),
grid.y.value_in(units.m)
)
xlim(-0.5,0.5)
ylim(-1,1)
```
```(-1, 1)
```

In[ ]:

07 - Channels

#### Next topic

Reference documentation