Efficient way to create occupancy grid map from VoxelGrid

I’m looking for an efficient way to create an 3D array containing the state given by the voxels within VoxelGrid. Of course I can do something like:

for voxel in voxel_grid:
    map[voxel.grid_index] = 1

Unfortunately this is very slow in case of larger environments.
Is there some better way that I’m missing?

Thanks in advance.