本文整理匯總了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)
示例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
示例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)
示例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)
示例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)