<commit_before># To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.

__author__ = "<NAME> <<EMAIL>>"
__date__ = "$Apr 30, 2014 5:14:50PM$"



# Generally useful and fast to import so done immediately.
import numpy

# Need in order to have logging information no matter what.
import debugging_tools


# Get the logger
logger = debugging_tools.logging.getLogger(__name__)


@debugging_tools.log_call(logger)
def zeroed_mean_images(input_array, output_array = None):
    """
        Takes and finds the mean for each image. Where each image is new_numpy_array[i] with some index i.
        
        Args:
            new_numpy_array(numpy.ndarray):     array images with time as the first index
            output_array(numpy.ndarray):        provides a location to store the result (optional)
        
        Returns:
            result(numpy.ndarray):              The same array with each images mean removed.
                                                Where means[i] = mean(new_numpy_array[i])
        
        
        Examples:
            >>> zeroed_mean_images(numpy.array([[0.,0.],[0.,0.]]))
            array([[ 0.,  0.],
                   [ 0.,  0.]])

            >>> zeroed_mean_images(numpy.array([[6.,0.],[0.,0.]]))
            array([[ 3., -3.],
                   [ 0.,  0.]])

            >>> zeroed_mean_images(numpy.array([[0.,0.],[0.,4.]]))
            array([[ 0.,  0.],
                   [-2.,  2.]])

            >>> zeroed_mean_images(numpy.array([[6.,0],[0.,4.]]))
            array([[ 3., -3.],
                   [-2.,  2.]])

            >>> zeroed_mean_images(numpy.array([[1.,2.],[3.,4.]]))
            array([[-0.5,  0.5],
                   [-0.5,  0.5]])

            >>> zeroed_mean_images(numpy.array([[1,2],[3,4]])) #doctest: +ELLIPSIS
            Traceback (most recent call last):
                ...
            AssertionError

            >>> zeroed_mean_images(numpy.array([[1,2],[3,4]]).astype(numpy.float32))
            array([[-0.5,  0.5],
                   [-0.5,  0.5]], dtype=float32)

            >>> a = numpy.array([[1.,2.],[3.,4.]]); numpy.all(a != zeroed_mean_images(a))
            True

            >>> a = numpy.array([[1.,2.],[3.,4.]]); numpy.all(a == zeroed_mean_images(a, output_array = a))
            True
    """
<commit_msg>nanshe/simple_image_processing.py: In zeroed_mean_images, added doctest for in-place calculation.<commit_after># To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.

__author__ = "<NAME> <<EMAIL>>"
__date__ = "$Apr 30, 2014 5:14:50PM$"



# Generally useful and fast to import so done immediately.
import numpy

# Need in order to have logging information no matter what.
import debugging_tools


# Get the logger
logger = debugging_tools.logging.getLogger(__name__)


@debugging_tools.log_call(logger)
def zeroed_mean_images(input_array, output_array = None):
    """
        Takes and finds the mean for each image. Where each image is new_numpy_array[i] with some index i.
        
        Args:
            new_numpy_array(numpy.ndarray):     array images with time as the first index
            output_array(numpy.ndarray):        provides a location to store the result (optional)
        
        Returns:
            result(numpy.ndarray):              The same array with each images mean removed.
                                                Where means[i] = mean(new_numpy_array[i])
        
        
        Examples:
            >>> zeroed_mean_images(numpy.array([[0.,0.],[0.,0.]]))
            array([[ 0.,  0.],
                   [ 0.,  0.]])

            >>> zeroed_mean_images(numpy.array([[6.,0.],[0.,0.]]))
            array([[ 3., -3.],
                   [ 0.,  0.]])

            >>> zeroed_mean_images(numpy.array([[0.,0.],[0.,4.]]))
            array([[ 0.,  0.],
                   [-2.,  2.]])

            >>> zeroed_mean_images(numpy.array([[6.,0],[0.,4.]]))
            array([[ 3., -3.],
                   [-2.,  2.]])

            >>> zeroed_mean_images(numpy.array([[1.,2.],[3.,4.]]))
            array([[-0.5,  0.5],
                   [-0.5,  0.5]])

            >>> zeroed_mean_images(numpy.array([[1,2],[3,4]])) #doctest: +ELLIPSIS
            Traceback (most recent call last):
                ...
            AssertionError

            >>> a = numpy.array([[1.,2.],[3.,4.]])
            >>> zeroed_mean_images(a, output_array=a)
            array([[-0.5,  0.5],
                   [-0.5,  0.5]])
            >>> a
            array([[-0.5,  0.5],
                   [-0.5,  0.5]])

            >>> zeroed_mean_images(numpy.array([[1,2],[3,4]]).astype(numpy.float32))
            array([[-0.5,  0.5],
                   [-0.5,  0.5]], dtype=float32)

            >>> a = numpy.array([[1.,2.],[3.,4.]]); numpy.all(a != zeroed_mean_images(a))
            True

            >>> a = numpy.array([[1.,2.],[3.,4.]]); numpy.all(a == zeroed_mean_images(a, output_array = a))
            True
    """

{'fraction_non_alphanumeric': 0.16466950135291844, 'fraction_numerical': 0.03594897564746811, 'mean_word_length': 1.765900587920898, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6867230', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1623, 'n_words': 368}