当前位置: 首页>>代码示例>>Python>>正文


Python numeric.newaxis方法代码示例

本文整理汇总了Python中numpy.core.numeric.newaxis方法的典型用法代码示例。如果您正苦于以下问题:Python numeric.newaxis方法的具体用法?Python numeric.newaxis怎么用?Python numeric.newaxis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.core.numeric的用法示例。


在下文中一共展示了numeric.newaxis方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _stack

# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import newaxis [as 别名]
def _stack(arrays, axis=0):
        arrays = [np.asanyarray(arr) for arr in arrays]
        if not arrays:
            raise ValueError('need at least one array to stack')

        shapes = set(arr.shape for arr in arrays)
        if len(shapes) != 1:
            raise ValueError('all input arrays must have the same shape')

        result_ndim = arrays[0].ndim + 1
        if not -result_ndim <= axis < result_ndim:
            msg = 'axis {0} out of bounds [-{1}, {1})'.format(axis, result_ndim)
            raise np.IndexError(msg)
        if axis < 0:
            axis += result_ndim

        sl = (slice(None),) * axis + (numeric.newaxis,)
        expanded_arrays = [arr[sl] for arr in arrays]
        return numeric.concatenate(expanded_arrays, axis=axis) 
开发者ID:comp-imaging,项目名称:ProxImaL,代码行数:21,代码来源:utils.py

示例2: estimate_std

# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import newaxis [as 别名]
def estimate_std(z, method='daub_reflect'):
    # Estimates noise standard deviation assuming additive gaussian noise

    # Check method
    if (method not in NoiseEstMethod.values()) and (method in NoiseEstMethod.keys()):
        method = NoiseEstMethod[method]
    else:
        raise Exception("Invalid noise estimation method.")

    # Check shape
    if len(z.shape) == 2:
        z = z[..., np.newaxis]
    elif len(z.shape) != 3:
        raise Exception("Supports only up to 3D images.")

    # Run on multichannel image
    channels = z.shape[2]
    dev = np.zeros(channels)

    # Iterate over channels
    for ch in range(channels):

        # Daubechies denoising method
        if method == NoiseEstMethod['daub_reflect'] or method == NoiseEstMethod['daub_replicate']:
            daub6kern = np.array([0.03522629188571, 0.08544127388203, -0.13501102001025,
                                  -0.45987750211849, 0.80689150931109, -0.33267055295008],
                                 dtype=np.float32, order='F')

            if method == NoiseEstMethod['daub_reflect']:
                wav_det = cv2.sepFilter2D(z, -1, daub6kern, daub6kern,
                                          borderType=cv2.BORDER_REFLECT_101)
            else:
                wav_det = cv2.sepFilter2D(z, -1, daub6kern, daub6kern,
                                          borderType=cv2.BORDER_REPLICATE)

            dev[ch] = np.median(np.absolute(wav_det)) / 0.6745

    # Return standard deviation
    return dev 
开发者ID:comp-imaging,项目名称:ProxImaL,代码行数:41,代码来源:utils.py

示例3: __getitem__

# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import newaxis [as 别名]
def __getitem__(self, key):
        try:
            size = []
            typ = int
            for k in range(len(key)):
                step = key[k].step
                start = key[k].start
                if start is None:
                    start = 0
                if step is None:
                    step = 1
                if isinstance(step, complex):
                    size.append(int(abs(step)))
                    typ = float
                else:
                    size.append(
                        int(math.ceil((key[k].stop - start)/(step*1.0))))
                if (isinstance(step, float) or
                        isinstance(start, float) or
                        isinstance(key[k].stop, float)):
                    typ = float
            if self.sparse:
                nn = [_nx.arange(_x, dtype=_t)
                        for _x, _t in zip(size, (typ,)*len(size))]
            else:
                nn = _nx.indices(size, typ)
            for k in range(len(size)):
                step = key[k].step
                start = key[k].start
                if start is None:
                    start = 0
                if step is None:
                    step = 1
                if isinstance(step, complex):
                    step = int(abs(step))
                    if step != 1:
                        step = (key[k].stop - start)/float(step-1)
                nn[k] = (nn[k]*step+start)
            if self.sparse:
                slobj = [_nx.newaxis]*len(size)
                for k in range(len(size)):
                    slobj[k] = slice(None, None)
                    nn[k] = nn[k][tuple(slobj)]
                    slobj[k] = _nx.newaxis
            return nn
        except (IndexError, TypeError):
            step = key.step
            stop = key.stop
            start = key.start
            if start is None:
                start = 0
            if isinstance(step, complex):
                step = abs(step)
                length = int(step)
                if step != 1:
                    step = (key.stop-start)/float(step-1)
                stop = key.stop + step
                return _nx.arange(0, length, 1, float)*step + start
            else:
                return _nx.arange(start, stop, step) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:62,代码来源:index_tricks.py

示例4: __getitem__

# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import newaxis [as 别名]
def __getitem__(self, key):
        try:
            size = []
            typ = int
            for k in range(len(key)):
                step = key[k].step
                start = key[k].start
                if start is None:
                    start = 0
                if step is None:
                    step = 1
                if isinstance(step, complex):
                    size.append(int(abs(step)))
                    typ = float
                else:
                    size.append(
                        int(math.ceil((key[k].stop - start)/(step*1.0))))
                if (isinstance(step, float) or
                        isinstance(start, float) or
                        isinstance(key[k].stop, float)):
                    typ = float
            if self.sparse:
                nn = [_nx.arange(_x, dtype=_t)
                        for _x, _t in zip(size, (typ,)*len(size))]
            else:
                nn = _nx.indices(size, typ)
            for k in range(len(size)):
                step = key[k].step
                start = key[k].start
                if start is None:
                    start = 0
                if step is None:
                    step = 1
                if isinstance(step, complex):
                    step = int(abs(step))
                    if step != 1:
                        step = (key[k].stop - start)/float(step-1)
                nn[k] = (nn[k]*step+start)
            if self.sparse:
                slobj = [_nx.newaxis]*len(size)
                for k in range(len(size)):
                    slobj[k] = slice(None, None)
                    nn[k] = nn[k][slobj]
                    slobj[k] = _nx.newaxis
            return nn
        except (IndexError, TypeError):
            step = key.step
            stop = key.stop
            start = key.start
            if start is None:
                start = 0
            if isinstance(step, complex):
                step = abs(step)
                length = int(step)
                if step != 1:
                    step = (key.stop-start)/float(step-1)
                stop = key.stop + step
                return _nx.arange(0, length, 1, float)*step + start
            else:
                return _nx.arange(start, stop, step) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:62,代码来源:index_tricks.py

示例5: __getitem__

# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import newaxis [as 别名]
def __getitem__(self, key):
        try:
            size = []
            typ = int
            for k in range(len(key)):
                step = key[k].step
                start = key[k].start
                if start is None: start=0
                if step is None: step=1
                if isinstance(step, complex):
                    size.append(int(abs(step)))
                    typ = float
                else:
                    size.append(int(math.ceil((key[k].stop - start)/(step*1.0))))
                if isinstance(step, float) or \
                    isinstance(start, float) or \
                    isinstance(key[k].stop, float):
                    typ = float
            if self.sparse:
                nn = [_nx.arange(_x, dtype=_t)
                        for _x, _t in zip(size, (typ,)*len(size))]
            else:
                nn = _nx.indices(size, typ)
            for k in range(len(size)):
                step = key[k].step
                start = key[k].start
                if start is None: start=0
                if step is None: step=1
                if isinstance(step, complex):
                    step = int(abs(step))
                    if step != 1:
                        step = (key[k].stop - start)/float(step-1)
                nn[k] = (nn[k]*step+start)
            if self.sparse:
                slobj = [_nx.newaxis]*len(size)
                for k in range(len(size)):
                    slobj[k] = slice(None, None)
                    nn[k] = nn[k][slobj]
                    slobj[k] = _nx.newaxis
            return nn
        except (IndexError, TypeError):
            step = key.step
            stop = key.stop
            start = key.start
            if start is None: start = 0
            if isinstance(step, complex):
                step = abs(step)
                length = int(step)
                if step != 1:
                    step = (key.stop-start)/float(step-1)
                stop = key.stop+step
                return _nx.arange(0, length, 1, float)*step + start
            else:
                return _nx.arange(start, stop, step) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:56,代码来源:index_tricks.py


注:本文中的numpy.core.numeric.newaxis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。