from .pointcloud import PointCloud
import numpy as np


def mean_pointcloud(pointclouds):
    r"""
    Compute the mean of a `list` of :map:`PointCloud` objects.

    Parameters
    ----------
    pointclouds: `list` of :map:`PointCloud`
        List of point cloud objects from which we want to compute the mean.

    Returns
    -------
    mean_pointcloud : :map:`PointCloud`
        The mean point cloud.
    """
    return PointCloud(np.mean([pc.points for pc in pointclouds], axis=0))

from __future__ import division
from .pointcloud import PointCloud


def mean_pointcloud(pointclouds):
    r"""
    Compute the mean of a `list` of :map:`PointCloud` objects.

    Parameters
    ----------
    pointclouds: `list` of :map:`PointCloud`
        List of point cloud objects from which we want to compute the mean.

    Returns
    -------
    mean_pointcloud : :map:`PointCloud`
        The mean point cloud.
    """
    return PointCloud(sum(pc.points for pc in pointclouds) / len(pointclouds))

Update mean_pointcloud to be faster
Update mean_pointcloud to be faster

This is actually faster than using numpy. It is also MUCH
faster if it gets jitted by something like pypy or numba.

+ from __future__ import division
  from .pointcloud import PointCloud
- import numpy as np
  
  
  def mean_pointcloud(pointclouds):
      r"""
      Compute the mean of a `list` of :map:`PointCloud` objects.
  
      Parameters
      ----------
      pointclouds: `list` of :map:`PointCloud`
          List of point cloud objects from which we want to compute the mean.
  
      Returns
      -------
      mean_pointcloud : :map:`PointCloud`
          The mean point cloud.
      """
-     return PointCloud(np.mean([pc.points for pc in pointclouds], axis=0))
+     return PointCloud(sum(pc.points for pc in pointclouds) / len(pointclouds))
  
Update mean_pointcloud to be faster
## Code Before:
from .pointcloud import PointCloud
import numpy as np


def mean_pointcloud(pointclouds):
    r"""
    Compute the mean of a `list` of :map:`PointCloud` objects.

    Parameters
    ----------
    pointclouds: `list` of :map:`PointCloud`
        List of point cloud objects from which we want to compute the mean.

    Returns
    -------
    mean_pointcloud : :map:`PointCloud`
        The mean point cloud.
    """
    return PointCloud(np.mean([pc.points for pc in pointclouds], axis=0))

## Instruction:
Update mean_pointcloud to be faster
## Code After:
from __future__ import division
from .pointcloud import PointCloud


def mean_pointcloud(pointclouds):
    r"""
    Compute the mean of a `list` of :map:`PointCloud` objects.

    Parameters
    ----------
    pointclouds: `list` of :map:`PointCloud`
        List of point cloud objects from which we want to compute the mean.

    Returns
    -------
    mean_pointcloud : :map:`PointCloud`
        The mean point cloud.
    """
    return PointCloud(sum(pc.points for pc in pointclouds) / len(pointclouds))
