本文整理汇总了Python中numpy.rollaxis方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.rollaxis方法的具体用法?Python numpy.rollaxis怎么用?Python numpy.rollaxis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.rollaxis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply_transform
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def apply_transform(x,
transform_matrix,
fill_mode='nearest',
cval=0.):
x = np.rollaxis(x, 0, 0)
final_affine_matrix = transform_matrix[:2, :2]
final_offset = transform_matrix[:2, 2]
channel_images = [ndi.interpolation.affine_transform(
x_channel,
final_affine_matrix,
final_offset,
order=0,
mode=fill_mode,
cval=cval) for x_channel in x]
x = np.stack(channel_images, axis=0)
x = np.rollaxis(x, 0, 0 + 1)
return x
示例2: _indices
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def _indices(self, slice_index=None):
# get a int-array containing all indices in the first axis.
if slice_index is None:
slice_index = self._current_slice_
#try:
indices = np.indices(self._realshape_, dtype=int)
indices = indices[(slice(None),)+slice_index]
indices = np.rollaxis(indices, 0, indices.ndim).reshape(-1,self._realndim_)
#print indices_
#if not np.all(indices==indices__):
# import ipdb; ipdb.set_trace()
#except:
# indices = np.indices(self._realshape_, dtype=int)
# indices = indices[(slice(None),)+slice_index]
# indices = np.rollaxis(indices, 0, indices.ndim)
return indices
示例3: _do_random_crop
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def _do_random_crop(self, image_array):
"""IMPORTANT: random crop only works for classification since the
current implementation does no transform bounding boxes"""
height = image_array.shape[0]
width = image_array.shape[1]
x_offset = np.random.uniform(0, self.translation_factor * width)
y_offset = np.random.uniform(0, self.translation_factor * height)
offset = np.array([x_offset, y_offset])
scale_factor = np.random.uniform(self.zoom_range[0],
self.zoom_range[1])
crop_matrix = np.array([[scale_factor, 0],
[0, scale_factor]])
image_array = np.rollaxis(image_array, axis=-1, start=0)
image_channel = [ndi.interpolation.affine_transform(image_channel,
crop_matrix, offset=offset, order=0, mode='nearest',
cval=0.0) for image_channel in image_array]
image_array = np.stack(image_channel, axis=0)
image_array = np.rollaxis(image_array, 0, 3)
return image_array
示例4: do_random_rotation
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def do_random_rotation(self, image_array):
"""IMPORTANT: random rotation only works for classification since the
current implementation does no transform bounding boxes"""
height = image_array.shape[0]
width = image_array.shape[1]
x_offset = np.random.uniform(0, self.translation_factor * width)
y_offset = np.random.uniform(0, self.translation_factor * height)
offset = np.array([x_offset, y_offset])
scale_factor = np.random.uniform(self.zoom_range[0],
self.zoom_range[1])
crop_matrix = np.array([[scale_factor, 0],
[0, scale_factor]])
image_array = np.rollaxis(image_array, axis=-1, start=0)
image_channel = [ndi.interpolation.affine_transform(image_channel,
crop_matrix, offset=offset, order=0, mode='nearest',
cval=0.0) for image_channel in image_array]
image_array = np.stack(image_channel, axis=0)
image_array = np.rollaxis(image_array, 0, 3)
return image_array
示例5: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def __init__(self, x, y, axis=0, extrapolate=None):
x = _asarray_validated(x, check_finite=False, as_inexact=True)
y = _asarray_validated(y, check_finite=False, as_inexact=True)
axis = axis % y.ndim
xp = x.reshape((x.shape[0],) + (1,)*(y.ndim-1))
yp = np.rollaxis(y, axis)
dk = self._find_derivatives(xp, yp)
data = np.hstack((yp[:, None, ...], dk[:, None, ...]))
_b = BPoly.from_derivatives(x, data, orders=None)
super(PchipInterpolator, self).__init__(_b.c, _b.x,
extrapolate=extrapolate)
self.axis = axis
示例6: create_spline
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def create_spline(y, yp, x, h):
"""Create a cubic spline given values and derivatives.
Formulas for the coefficients are taken from interpolate.CubicSpline.
Returns
-------
sol : PPoly
Constructed spline as a PPoly instance.
"""
from scipy.interpolate import PPoly
n, m = y.shape
c = np.empty((4, n, m - 1), dtype=y.dtype)
slope = (y[:, 1:] - y[:, :-1]) / h
t = (yp[:, :-1] + yp[:, 1:] - 2 * slope) / h
c[0] = t / h
c[1] = (slope - yp[:, :-1]) / h - t
c[2] = yp[:, :-1]
c[3] = y[:, :-1]
c = np.rollaxis(c, 1)
return PPoly(c, x, extrapolate=True, axis=1)
示例7: _nanpercentile
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def _nanpercentile(a, q, axis=None, out=None, overwrite_input=False,
interpolation='linear'):
"""
Private function that doesn't support extended axis or keepdims.
These methods are extended to this function using _ureduce
See nanpercentile for parameter usage
"""
if axis is None or a.ndim == 1:
part = a.ravel()
result = _nanpercentile1d(part, q, overwrite_input, interpolation)
else:
result = np.apply_along_axis(_nanpercentile1d, axis, a, q,
overwrite_input, interpolation)
# apply_along_axis fills in collapsed axis with results.
# Move that axis to the beginning to match percentile's
# convention.
if q.ndim != 0:
result = np.rollaxis(result, axis)
if out is not None:
out[...] = result
return result
示例8: _nanpercentile
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def _nanpercentile(a, q, axis=None, out=None, overwrite_input=False,
interpolation='linear'):
"""
Private function that doesn't support extended axis or keepdims.
These methods are extended to this function using _ureduce
See nanpercentile for parameter usage
"""
if axis is None:
part = a.ravel()
result = _nanpercentile1d(part, q, overwrite_input, interpolation)
else:
result = np.apply_along_axis(_nanpercentile1d, axis, a, q,
overwrite_input, interpolation)
# apply_along_axis fills in collapsed axis with results.
# Move that axis to the beginning to match percentile's
# convention.
if q.ndim != 0:
result = np.rollaxis(result, axis)
if out is not None:
out[...] = result
return result
示例9: SVHN_dataload
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def SVHN_dataload():
import numpy as np
import scipy.io as sio
import os
pathname = 'data/SVHN'
fn = 'train_32x32.mat'
loaddata = sio.loadmat(os.path.join(pathname, fn))
Traindata = loaddata['X']
trainlabel = loaddata['y']
Traindata = np.rollaxis(Traindata, 3, 0)
fn = 'test_32x32.mat'
loadtdata = sio.loadmat(os.path.join(pathname, fn))
Testdata = loadtdata['X']
testlabel = loadtdata['y']
Testdata = np.rollaxis(Testdata, 3, 0)
return Traindata, trainlabel, Testdata, testlabel
# %% MNIST-M load
示例10: synthetic_digits_small_dataload
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def synthetic_digits_small_dataload():
import os
import scipy.io as sio
import numpy as np
filepath = '/home/damodara/OT/DA/datasets/SynthDigits'
train_fname = os.path.join(filepath, 'synth_train_32x32_small.mat')
loaddata = sio.loadmat(train_fname)
Traindata = loaddata['X']
train_label = loaddata['y']
#
test_fname = os.path.join(filepath, 'synth_test_32x32_small.mat')
loaddata = sio.loadmat(test_fname)
Testdata = loaddata['X']
test_label = loaddata['y']
Traindata = np.rollaxis(Traindata, 3, 0)
Testdata = np.rollaxis(Testdata, 3, 0)
return Traindata, train_label, Testdata, test_label
示例11: synthetic_digits_dataload
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def synthetic_digits_dataload():
import os
import scipy.io as sio
import numpy as np
filepath = '/home/damodara/OT/DA/datasets/SynthDigits'
train_fname = os.path.join(filepath, 'synth_train_32x32.mat')
loaddata = sio.loadmat(train_fname)
Traindata = loaddata['X']
train_label = loaddata['y']
#
test_fname = os.path.join(filepath, 'synth_test_32x32.mat')
loaddata = sio.loadmat(test_fname)
Testdata = loaddata['X']
test_label = loaddata['y']
Traindata = np.rollaxis(Traindata, 3, 0)
Testdata = np.rollaxis(Testdata, 3, 0)
return Traindata, train_label, Testdata, test_label
# %% stl9
示例12: multi_label_img_to_multi_hot
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def multi_label_img_to_multi_hot(np_array):
"""
TODO: There must be a faster way of doing this + ajust to correct input format (see gt_tensor_to_one_hot)
Convert ground truth label image to multi-one-hot encoded matrix of size image height x image width x #classes
Parameters
-------
np_array: numpy array
RGB image [W x H x C]
Returns
-------
numpy array of size [#C x W x H]
sparse one-hot encoded multi-class matrix, where #C is the number of classes
"""
im_np = np_array[:, :, 2].astype(np.int8)
nb_classes = len(int_to_one_hot(im_np.max(), ''))
class_dict = {x: int_to_one_hot(x, nb_classes) for x in np.unique(im_np)}
# create the one hot matrix
one_hot_matrix = np.asanyarray(
[[class_dict[im_np[i, j]] for j in range(im_np.shape[1])] for i in range(im_np.shape[0])])
return np.rollaxis(one_hot_matrix.astype(np.uint8), 2, 0)
示例13: multi_one_hot_to_output
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def multi_one_hot_to_output(matrix):
"""
This function converts the multi-one-hot encoded matrix to an image like it was provided in the ground truth
Parameters
-------
tensor of size [#C x W x H]
sparse one-hot encoded multi-class matrix, where #C is the number of classes
Returns
-------
np_array: numpy array
RGB image [C x W x H]
"""
# TODO: fix input and output dims (see one_hot_to_output)
# create RGB
matrix = np.rollaxis(np.char.mod('%d', matrix.numpy()), 0, 3)
zeros = (32 - matrix.shape[2]) * '0'
B = np.array([[int('{}{}'.format(zeros, ''.join(matrix[i][j])), 2) for j in range(matrix.shape[1])] for i in
range(matrix.shape[0])])
RGB = np.dstack((np.zeros(shape=(matrix.shape[0], matrix.shape[1], 2), dtype=np.int8), B))
return RGB
示例14: _do_random_crop
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def _do_random_crop(self, image_array):
"""IMPORTANT: random crop only works for classification since the
current implementation does no transform bounding boxes"""
height = image_array.shape[0]
width = image_array.shape[1]
x_offset = np.random.uniform(0, self.translation_factor * width)
y_offset = np.random.uniform(0, self.translation_factor * height)
offset = np.array([x_offset, y_offset])
scale_factor = np.random.uniform(self.zoom_range[0],
self.zoom_range[1])
crop_matrix = np.array([[scale_factor, 0],
[0, scale_factor]])
image_array = np.rollaxis(image_array, axis=-1, start=0)
image_channel = [ndi.interpolation.affine_transform(image_channel,
crop_matrix, offset=offset, order=0, mode='nearest',
cval=0.0) for image_channel in image_array]
image_array = np.stack(image_channel, axis=0)
image_array = np.rollaxis(image_array, 0, 3)
return image_array
示例15: do_random_rotation
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import rollaxis [as 别名]
def do_random_rotation(self, image_array):
"""IMPORTANT: random rotation only works for classification since the
current implementation does no transform bounding boxes"""
height = image_array.shape[0]
width = image_array.shape[1]
x_offset = np.random.uniform(0, self.translation_factor * width)
y_offset = np.random.uniform(0, self.translation_factor * height)
offset = np.array([x_offset, y_offset])
scale_factor = np.random.uniform(self.zoom_range[0],
self.zoom_range[1])
crop_matrix = np.array([[scale_factor, 0],
[0, scale_factor]])
image_array = np.rollaxis(image_array, axis=-1, start=0)
image_channel = [ndi.interpolation.affine_transform(image_channel,
crop_matrix, offset=offset, order=0, mode='nearest',
cval=0.0) for image_channel in image_array]
image_array = np.stack(image_channel, axis=0)
image_array = np.rollaxis(image_array, 0, 3)
return image_array