本文整理匯總了Python中numpy.rot90方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.rot90方法的具體用法?Python numpy.rot90怎麽用?Python numpy.rot90使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.rot90方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: show
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def show():
"""Output the contents of the buffer to Unicorn HAT HD."""
setup()
if _addressing_enabled:
for address in range(8):
display = _displays[address]
if display.enabled:
if _buffer_width == _buffer_height or _rotation in [0, 2]:
window = display.get_buffer_window(numpy.rot90(_buf, _rotation))
else:
window = display.get_buffer_window(numpy.rot90(_buf, _rotation))
_spi.xfer2([_SOF + 1 + address] + (window.reshape(768) * _brightness).astype(numpy.uint8).tolist())
time.sleep(_DELAY)
else:
_spi.xfer2([_SOF] + (numpy.rot90(_buf, _rotation).reshape(768) * _brightness).astype(numpy.uint8).tolist())
time.sleep(_DELAY)
示例2: augment_img
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def augment_img(img, mode=0):
'''Kai Zhang (github: https://github.com/cszn)
'''
if mode == 0:
return img
elif mode == 1:
return np.flipud(np.rot90(img))
elif mode == 2:
return np.flipud(img)
elif mode == 3:
return np.rot90(img, k=3)
elif mode == 4:
return np.flipud(np.rot90(img, k=2))
elif mode == 5:
return np.rot90(img)
elif mode == 6:
return np.rot90(img, k=2)
elif mode == 7:
return np.flipud(np.rot90(img, k=3))
示例3: augment_img_tensor4
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def augment_img_tensor4(img, mode=0):
'''Kai Zhang (github: https://github.com/cszn)
'''
if mode == 0:
return img
elif mode == 1:
return img.rot90(1, [2, 3]).flip([2])
elif mode == 2:
return img.flip([2])
elif mode == 3:
return img.rot90(3, [2, 3])
elif mode == 4:
return img.rot90(2, [2, 3]).flip([2])
elif mode == 5:
return img.rot90(1, [2, 3])
elif mode == 6:
return img.rot90(2, [2, 3])
elif mode == 7:
return img.rot90(3, [2, 3]).flip([2])
示例4: augment_imgs
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def augment_imgs(img_list, hflip=True, rot=True):
# horizontal flip OR rotate
hflip = hflip and random.random() < 0.5
vflip = rot and random.random() < 0.5
rot90 = rot and random.random() < 0.5
def _augment(img):
if hflip:
img = img[:, ::-1, :]
if vflip:
img = img[::-1, :, :]
if rot90:
img = img.transpose(1, 0, 2)
return img
return [_augment(img) for img in img_list]
示例5: rotate_patches
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rotate_patches(patches_vol, patches_seg):
# Initialize lists for rotated patches
rotated_vol = []
rotated_seg = []
# Iterate over 90,180,270 degree (1*90, 2*90, 3*90)
for times in range(1,4):
# Iterate over each patch
for i in range(len(patches_vol)):
# Rotate volume & segmentation and cache rotated patches
patch_vol_rotated = np.rot90(patches_vol[i], k=times, axes=(2,3))
rotated_vol.append(patch_vol_rotated)
patch_seg_rotated = np.rot90(patches_seg[i], k=times, axes=(2,3))
rotated_seg.append(patch_seg_rotated)
# Add rotated patches to the original patches lists
patches_vol.extend(rotated_vol)
patches_seg.extend(rotated_seg)
# Return processed patches lists
return patches_vol, patches_seg
# Flip patches at the provided axes
示例6: data_aug
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def data_aug(img, mode=0):
# data augmentation
if mode == 0:
return img
elif mode == 1:
return np.flipud(img)
elif mode == 2:
return np.rot90(img)
elif mode == 3:
return np.flipud(np.rot90(img))
elif mode == 4:
return np.rot90(img, k=2)
elif mode == 5:
return np.flipud(np.rot90(img, k=2))
elif mode == 6:
return np.rot90(img, k=3)
elif mode == 7:
return np.flipud(np.rot90(img, k=3))
示例7: rot90
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rot90(m, k=1, axes=(0, 1)): # pylint: disable=missing-docstring
m_rank = tf.rank(m)
ax1, ax2 = utils._canonicalize_axes(axes, m_rank) # pylint: disable=protected-access
k = k % 4
if k == 0:
return m
elif k == 2:
return flip(flip(m, ax1), ax2)
else:
perm = tf.range(m_rank)
perm = tf.tensor_scatter_nd_update(perm, [[ax1], [ax2]], [ax2, ax1])
if k == 1:
return transpose(flip(m, ax2), perm)
else:
return flip(transpose(m, perm), ax2)
示例8: _create_bowl
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def _create_bowl(self, altitude_changes):
half_width = len(altitude_changes)
height = sum(altitude_changes) + 1
half_bowl = np.zeros((height, half_width))
row = 0
for idx, ac in enumerate(altitude_changes):
half_bowl[row, idx] = 1
for i in xrange(ac):
row += 1
half_bowl[row, idx] = 1
assert row == height-1
bowl = np.concatenate([half_bowl, np.fliplr(half_bowl)], axis=1)
for _ in range(self.rotations):
bowl = np.rot90(bowl)
return bowl
示例9: rot180
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rot180(images):
"""
旋轉圖片180度。
支持HW/CHW/NCHW三種格式的images。
"""
out = np.empty(shape=images.shape, dtype=images.dtype)
if images.ndim == 2:
out = np.rot90(images, k=2)
elif images.ndim == 3:
for c in xrange(images.shape[0]):
out[c] = np.rot90(images[c], k=2)
elif images.ndim == 4:
for n in xrange(images.shape[0]):
for c in xrange(images.shape[1]):
out[n][c] = np.rot90(images[n][c], k=2)
else:
raise Exception('Invalid ndim: ' + str(images.ndim) +
', only support ndim between 2 and 4.')
return out
# 給定函數f,自變量x以及對f的梯度df,求對x的梯度
示例10: _apply_transformations
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def _apply_transformations(plot_config, data_slice):
"""Rotate, flip and zoom the data slice.
Depending on the plot configuration, this will apply some transformations to the given data slice.
Args:
plot_config (mdt.visualization.maps.base.MapPlotConfig): the plot configuration
data_slice (ndarray): the 2d slice of data to transform
Returns:
ndarray: the transformed 2d slice of data
"""
if plot_config.rotate:
data_slice = np.rot90(data_slice, plot_config.rotate // 90)
if not plot_config.flipud:
# by default we flipud to correct for matplotlib lower origin. If the user
# sets flipud, we do not need to to it
data_slice = np.flipud(data_slice)
data_slice = plot_config.zoom.apply(data_slice)
return data_slice
示例11: get_buffer_window
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def get_buffer_window(self, source):
"""Grab the correct portion of the supplied buffer for this display.
:param source: source buffer, should be a numpy array
"""
view = source[self.x:self.x + PANEL_SHAPE[0], self.y:self.y + PANEL_SHAPE[1]]
return numpy.rot90(view, self.rotation + 1)
示例12: cce2full
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def cce2full(A):
# Assume all square for now
N = A.shape
N_half = N[0]//2 + 1
out = np.empty((A.shape[0], A.shape[0]), dtype=A.dtype)
out[:, :N_half] = A
out[1:, N_half:] = np.rot90(A[1:, 1:-1], 2).conj()
# Complete the first row
out[0, N_half:] = A[0, -2:0:-1].conj()
return out
示例13: augment_data
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def augment_data(self, game_state, training_data, row, column):
"""Loop for each self-play game.
Runs MCTS for each game state and plays a move based on the MCTS output.
Stops when the game is over and prints out a winner.
Args:
game_state: An object containing the state, pis and value.
training_data: A list to store self play states, pis and vs.
row: An integer indicating the length of the board row.
column: An integer indicating the length of the board column.
"""
state = deepcopy(game_state[0])
psa_vector = deepcopy(game_state[1])
if CFG.game == 2 or CFG.game == 1:
training_data.append([state, psa_vector, game_state[2]])
else:
psa_vector = np.reshape(psa_vector, (row, column))
# Augment data by rotating and flipping the game state.
for i in range(4):
training_data.append([np.rot90(state, i),
np.rot90(psa_vector, i).flatten(),
game_state[2]])
training_data.append([np.fliplr(np.rot90(state, i)),
np.fliplr(
np.rot90(psa_vector, i)).flatten(),
game_state[2]])
示例14: rotate
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rotate(images):
images = np.append(images, [np.fliplr(image) for image in images], axis=0) # 180 degree
images = np.append(images, [np.rot90(image) for image in images], axis=0) # 90 degree
return images
示例15: rotate
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rotate(image, angle, axes=(0, 1)):
if angle % 90 != 0:
raise Exception('Angle must be a multiple of 90.')
k = angle // 90
return np.rot90(image, k, axes=axes)