Python numpy.ma.power() Examples

The following are 30 code examples of numpy.ma.power(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module numpy.ma , or try the search function .
Example #1
Source File: mstats_basic.py    From Computable with MIT License 6 votes vote down vote up
def moment(a, moment=1, axis=0):
    a, axis = _chk_asarray(a, axis)
    if moment == 1:
        # By definition the first moment about the mean is 0.
        shape = list(a.shape)
        del shape[axis]
        if shape:
            # return an actual array of the appropriate shape
            return np.zeros(shape, dtype=float)
        else:
            # the input was 1D, so return a scalar instead of a rank-0 array
            return np.float64(0.0)
    else:
        mn = ma.expand_dims(a.mean(axis=axis), axis)
        s = ma.power((a-mn), moment)
        return s.mean(axis=axis) 
Example #2
Source File: mstats_basic.py    From Computable with MIT License 6 votes vote down vote up
def kurtosistest(a, axis=0):
    a, axis = _chk_asarray(a, axis)
    n = a.count(axis=axis).astype(float)
    if np.min(n) < 20:
        warnings.warn(
            "kurtosistest only valid for n>=20 ... continuing anyway, n=%i" %
            np.min(n))
    b2 = kurtosis(a, axis, fisher=False)
    E = 3.0*(n-1) / (n+1)
    varb2 = 24.0*n*(n-2)*(n-3) / ((n+1)*(n+1)*(n+3)*(n+5))
    x = (b2-E)/ma.sqrt(varb2)
    sqrtbeta1 = 6.0*(n*n-5*n+2)/((n+7)*(n+9)) * np.sqrt((6.0*(n+3)*(n+5)) /
                                                        (n*(n-2)*(n-3)))
    A = 6.0 + 8.0/sqrtbeta1 * (2.0/sqrtbeta1 + np.sqrt(1+4.0/(sqrtbeta1**2)))
    term1 = 1 - 2./(9.0*A)
    denom = 1 + x*ma.sqrt(2/(A-4.0))
    denom[denom < 0] = masked
    term2 = ma.power((1-2.0/A)/denom,1/3.0)
    Z = (term1 - term2) / np.sqrt(2/(9.0*A))
    return Z, (1.0-stats.zprob(Z))*2 
Example #3
Source File: scale.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(self.base, a) 
Example #4
Source File: scale.py    From neural-network-animation with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(self.base, a) / self.base 
Example #5
Source File: scale.py    From neural-network-animation with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        sign = np.sign(a)
        masked = ma.masked_inside(a, -self.invlinthresh,
                                  self.invlinthresh, copy=False)
        exp = sign * self.linthresh * (
            ma.power(self.base, (sign * (masked / self.linthresh))
            - self._linscale_adj))
        if masked.mask.any():
            return ma.where(masked.mask, a / self._linscale_adj, exp)
        else:
            return exp 
Example #6
Source File: colors.py    From neural-network-animation with MIT License 5 votes vote down vote up
def __call__(self, value, clip=None):
        if clip is None:
            clip = self.clip

        result, is_scalar = self.process_value(value)

        self.autoscale_None(result)
        gamma = self.gamma
        vmin, vmax = self.vmin, self.vmax
        if vmin > vmax:
            raise ValueError("minvalue must be less than or equal to maxvalue")
        elif vmin == vmax:
            result.fill(0)
        else:
            res_mask = result.data < 0
            if clip:
                mask = ma.getmask(result)
                result = ma.array(np.clip(result.filled(vmax), vmin, vmax),
                                  mask=mask)
            resdat = result.data
            resdat -= vmin
            np.power(resdat, gamma, resdat)
            resdat /= (vmax - vmin) ** gamma

            result = np.ma.array(resdat, mask=result.mask, copy=False)
            result[res_mask] = 0
        if is_scalar:
            result = result[0]
        return result 
Example #7
Source File: colors.py    From neural-network-animation with MIT License 5 votes vote down vote up
def inverse(self, value):
        if not self.scaled():
            raise ValueError("Not invertible until scaled")
        gamma = self.gamma
        vmin, vmax = self.vmin, self.vmax

        if cbook.iterable(value):
            val = ma.asarray(value)
            return ma.power(value, 1. / gamma) * (vmax - vmin) + vmin
        else:
            return pow(value, 1. / gamma) * (vmax - vmin) + vmin 
Example #8
Source File: scale.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(self.base, a) 
Example #9
Source File: scale.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        sign = np.sign(a)
        masked = ma.masked_inside(a, -self.invlinthresh,
                                  self.invlinthresh, copy=False)
        exp = sign * self.linthresh * (
            ma.power(self.base, (sign * (masked / self.linthresh))
            - self._linscale_adj))
        if masked.mask.any():
            return ma.where(masked.mask, a / self._linscale_adj, exp)
        else:
            return exp 
Example #10
Source File: scale.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(self.base, a) 
Example #11
Source File: scale.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def transform_non_affine(self, a):
        sign = np.sign(a)
        masked = ma.masked_inside(a, -self.invlinthresh,
                                  self.invlinthresh, copy=False)
        exp = sign * self.linthresh * (
            ma.power(self.base, (sign * (masked / self.linthresh))
            - self._linscale_adj))
        if masked.mask.any():
            return ma.where(masked.mask, a / self._linscale_adj, exp)
        else:
            return exp 
Example #12
Source File: scale.py    From neural-network-animation with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(np.e, a) / np.e 
Example #13
Source File: scale.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        sign = np.sign(a)
        masked = ma.masked_inside(a, -self.invlinthresh,
                                  self.invlinthresh, copy=False)
        exp = sign * self.linthresh * (
            ma.power(self.base, (sign * (masked / self.linthresh))
            - self._linscale_adj))
        if masked.mask.any():
            return ma.where(masked.mask, a / self._linscale_adj, exp)
        else:
            return exp 
Example #14
Source File: scale.py    From CogAlg with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(self.base, a) 
Example #15
Source File: scale.py    From CogAlg with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(self.base, a) 
Example #16
Source File: scale.py    From CogAlg with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        abs_a = np.abs(a)
        with np.errstate(divide="ignore", invalid="ignore"):
            out = np.sign(a) * self.linthresh * (
                np.power(self.base,
                         abs_a / self.linthresh - self._linscale_adj))
            inside = abs_a <= self.invlinthresh
        out[inside] = a[inside] / self._linscale_adj
        return out 
Example #17
Source File: scale.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(self.base, a) 
Example #18
Source File: scale.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        sign = np.sign(a)
        masked = ma.masked_inside(a, -self.invlinthresh,
                                  self.invlinthresh, copy=False)
        exp = sign * self.linthresh * (
            ma.power(self.base, (sign * (masked / self.linthresh))
            - self._linscale_adj))
        if masked.mask.any():
            return ma.where(masked.mask, a / self._linscale_adj, exp)
        else:
            return exp 
Example #19
Source File: scale.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(np.e, a) / np.e 
Example #20
Source File: scale.py    From Computable with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(10.0, a) / 10.0 
Example #21
Source File: scale.py    From Computable with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(2.0, a) / 2.0 
Example #22
Source File: scale.py    From Computable with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(np.e, a) / np.e 
Example #23
Source File: scale.py    From Computable with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(self.base, a) / self.base 
Example #24
Source File: scale.py    From Computable with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        sign = np.sign(a)
        masked = ma.masked_inside(a, -self.invlinthresh,
                                  self.invlinthresh, copy=False)
        exp = sign * self.linthresh * (
            ma.power(self.base, (sign * (masked / self.linthresh))
            - self._linscale_adj))
        if masked.mask.any():
            return ma.where(masked.mask, a / self._linscale_adj, exp)
        else:
            return exp 
Example #25
Source File: scale.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(10.0, a) / 10.0 
Example #26
Source File: scale.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(2.0, a) / 2.0 
Example #27
Source File: scale.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(self.base, a) / self.base 
Example #28
Source File: scale.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        sign = np.sign(a)
        masked = ma.masked_inside(a, -self.invlinthresh,
                                  self.invlinthresh, copy=False)
        exp = sign * self.linthresh * (
            ma.power(self.base, (sign * (masked / self.linthresh))
            - self._linscale_adj))
        if masked.mask.any():
            return ma.where(masked.mask, a / self._linscale_adj, exp)
        else:
            return exp 
Example #29
Source File: scale.py    From neural-network-animation with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(10.0, a) / 10.0 
Example #30
Source File: scale.py    From neural-network-animation with MIT License 5 votes vote down vote up
def transform_non_affine(self, a):
        return ma.power(2.0, a) / 2.0