本文整理汇总了Python中numpy.flipud方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.flipud方法的具体用法?Python numpy.flipud怎么用?Python numpy.flipud使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.flipud方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quadrature_cc_1D
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def quadrature_cc_1D(N):
""" Computes the Clenshaw Curtis nodes and weights """
N = np.int(N)
if N == 1:
knots = 0
weights = 2
else:
n = N - 1
C = np.zeros((N,2))
k = 2*(1+np.arange(np.floor(n/2)))
C[::2,0] = 2/np.hstack((1, 1-k*k))
C[1,1] = -n
V = np.vstack((C,np.flipud(C[1:n,:])))
F = np.real(ifft(V, n=None, axis=0))
knots = F[0:N,1]
weights = np.hstack((F[0,0],2*F[1:n,0],F[n,0]))
return knots, weights
示例2: convert_image
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def convert_image(self, filename):
pic = img.imread(filename)
# Set FFT size to be double the image size so that the edge of the spectrum stays clear
# preventing some bandfilter artifacts
self.NFFT = 2*pic.shape[1]
# Repeat image lines until each one comes often enough to reach the desired line time
ffts = (np.flipud(np.repeat(pic[:, :, 0], self.repetitions, axis=0) / 16.)**2.) / 256.
# Embed image in center bins of the FFT
fftall = np.zeros((ffts.shape[0], self.NFFT))
startbin = int(self.NFFT/4)
fftall[:, startbin:(startbin+pic.shape[1])] = ffts
# Generate random phase vectors for the FFT bins, this is important to prevent high peaks in the output
# The phases won't be visible in the spectrum
phases = 2*np.pi*np.random.rand(*fftall.shape)
rffts = fftall * np.exp(1j*phases)
# Perform the FFT per image line, then concatenate them to form the final signal
timedata = np.fft.ifft(np.fft.ifftshift(rffts, axes=1), axis=1) / np.sqrt(float(self.NFFT))
linear = timedata.flatten()
linear = linear / np.max(np.abs(linear))
return linear
示例3: save_movie_to_frame
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def save_movie_to_frame(images, filename, idx=0, cmap='Blues'):
# Collect to single image
image = movie_to_frame(images[idx])
# Flip it
# image = np.fliplr(image)
# image = np.flipud(image)
f = plt.figure(figsize=[12, 12])
plt.imshow(image, cmap=plt.cm.get_cmap(cmap), interpolation='none', vmin=0, vmax=1)
plt.axis('image')
plt.xticks([])
plt.yticks([])
plt.savefig(filename, format='png', bbox_inches='tight', dpi=80)
plt.close(f)
示例4: test_flip_axis
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def test_flip_axis():
a = np.arange(24).reshape((2,3,4))
assert_array_equal(
flip_axis(a),
np.flipud(a))
assert_array_equal(
flip_axis(a, axis=0),
np.flipud(a))
assert_array_equal(
flip_axis(a, axis=1),
np.fliplr(a))
# check accepts array-like
assert_array_equal(
flip_axis(a.tolist(), axis=0),
np.flipud(a))
# third dimension
b = a.transpose()
b = np.flipud(b)
b = b.transpose()
assert_array_equal(flip_axis(a, axis=2), b)
示例5: test_closest_canonical
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def test_closest_canonical():
arr = np.arange(24).reshape((2,3,4,1))
# no funky stuff, returns same thing
img = Nifti1Image(arr, np.eye(4))
xyz_img = as_closest_canonical(img)
assert_true(img is xyz_img)
# a axis flip
img = Nifti1Image(arr, np.diag([-1,1,1,1]))
xyz_img = as_closest_canonical(img)
assert_false(img is xyz_img)
out_arr = xyz_img.get_data()
assert_array_equal(out_arr, np.flipud(arr))
# no error for enforce_diag in this case
xyz_img = as_closest_canonical(img, True)
# but there is if the affine is not diagonal
aff = np.eye(4)
aff[0,1] = 0.1
# although it's more or less canonical already
img = Nifti1Image(arr, aff)
xyz_img = as_closest_canonical(img)
assert_true(img is xyz_img)
# it's still not diagnonal
assert_raises(OrientationError, as_closest_canonical, img, True)
示例6: decompose_projection_matrix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def decompose_projection_matrix(P, return_t=True):
if P.shape[0] != 3 or P.shape[1] != 4:
raise Exception('P has to be 3x4')
M = P[:, :3]
C = -np.linalg.inv(M) @ P[:, 3:]
R,K = np.linalg.qr(np.flipud(M).T)
K = np.flipud(K.T)
K = np.fliplr(K)
R = np.flipud(R.T)
T = np.diag(np.sign(np.diag(K)))
K = K @ T
R = T @ R
if np.linalg.det(R) < 0:
R *= -1
K /= K[2,2]
if return_t:
return K, R, cameracenter_to_translation(R, C)
else:
return K, R, C
示例7: draw_lane_fit
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def draw_lane_fit(undist, warped ,Minv, left_fitx, right_fitx, ploty):
# Drawing
# Create an image to draw the lines on
warp_zero = np.zeros_like(warped).astype(np.uint8)
color_warp = np.dstack((warp_zero, warp_zero, warp_zero))
# Recast the x and y points into usable format for cv2.fillPoly()
pts_left = np.array([np.transpose(np.vstack([left_fitx, ploty]))])
pts_right = np.array([np.flipud(np.transpose(np.vstack([right_fitx, ploty])))])
pts = np.hstack((pts_left, pts_right))
# Draw the lane onto the warped blank image
cv2.fillPoly(color_warp, np.int_([pts]), (0,255,0))
# Warp the blank back to original image space using inverse perspective matrix(Minv)
newwarp = cv2.warpPerspective(color_warp, Minv, (undist.shape[1], undist.shape[0]))
# Combine the result with the original image
result = cv2.addWeighted(undist, 1, newwarp, 0.3, 0)
return result
示例8: calc_axon_contribution
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def calc_axon_contribution(self, axons):
xyret = np.column_stack((self.grid.xret.ravel(),
self.grid.yret.ravel()))
# Only include axon segments that are < `max_d2` from the soma. These
# axon segments will have `sensitivity` > `self.min_ax_sensitivity`:
max_d2 = -2.0 * self.axlambda ** 2 * np.log(self.min_ax_sensitivity)
axon_contrib = []
for xy, bundle in zip(xyret, axons):
idx = np.argmin((bundle[:, 0] - xy[0]) ** 2 +
(bundle[:, 1] - xy[1]) ** 2)
# Cut off the part of the fiber that goes beyond the soma:
axon = np.flipud(bundle[0: idx + 1, :])
# Add the exact location of the soma:
axon = np.insert(axon, 0, xy, axis=0)
# For every axon segment, calculate distance from soma by
# summing up the individual distances between neighboring axon
# segments (by "walking along the axon"):
d2 = np.cumsum(np.diff(axon[:, 0], axis=0) ** 2 +
np.diff(axon[:, 1], axis=0) ** 2)
idx_d2 = d2 < max_d2
sensitivity = np.exp(-d2[idx_d2] / (2.0 * self.axlambda ** 2))
idx_d2 = np.insert(idx_d2, 0, False)
contrib = np.column_stack((axon[idx_d2, :], sensitivity))
axon_contrib.append(contrib)
return axon_contrib
示例9: rank_sites_by_record_count
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def rank_sites_by_record_count(database, threshold=0):
"""
Function to determine count the number of records per site and return
the list ranked in descending order
"""
name_id_list = [(rec.site.id, rec.site.name) for rec in database.records]
name_id = dict([])
for name_id_pair in name_id_list:
if name_id_pair[0] in name_id:
name_id[name_id_pair[0]]["Count"] += 1
else:
name_id[name_id_pair[0]] = {"Count": 1, "Name": name_id_pair[1]}
counts = np.array([name_id[key]["Count"] for key in name_id])
sort_id = np.flipud(np.argsort(counts))
key_vals = list(name_id)
output_list = []
for idx in sort_id:
if name_id[key_vals[idx]]["Count"] >= threshold:
output_list.append((key_vals[idx], name_id[key_vals[idx]]))
return OrderedDict(output_list)
示例10: save_pfm
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def save_pfm(fname, image, scale=1):
file = open(fname, 'w')
color = None
if image.dtype.name != 'float32':
raise Exception('Image dtype must be float32.')
if len(image.shape) == 3 and image.shape[2] == 3: # color image
color = True
elif len(image.shape) == 2 or len(image.shape) == 3 and image.shape[2] == 1: # greyscale
color = False
else:
raise Exception('Image must have H x W x 3, H x W x 1 or H x W dimensions.')
file.write('PF\n' if color else 'Pf\n')
file.write('%d %d\n' % (image.shape[1], image.shape[0]))
endian = image.dtype.byteorder
if endian == '<' or endian == '=' and sys.byteorder == 'little':
scale = -scale
file.write('%f\n' % scale)
np.flipud(image).tofile(file)
示例11: augment_img
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [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))
示例12: update
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def update(self):
if self.inky_colour is None:
raise RuntimeError("You must specify which colour of Inky pHAT you're using: inkyphat.set_colour('red', 'black' or 'yellow')")
self._display_init()
x1, x2 = self.update_x1, self.update_x2
y1, y2 = self.update_y1, self.update_y2
region = self.buffer[y1:y2, x1:x2]
if self.v_flip:
region = numpy.fliplr(region)
if self.h_flip:
region = numpy.flipud(region)
buf_red = numpy.packbits(numpy.where(region == RED, 1, 0)).tolist()
if self.inky_version == 1:
buf_black = numpy.packbits(numpy.where(region == 0, 0, 1)).tolist()
else:
buf_black = numpy.packbits(numpy.where(region == BLACK, 0, 1)).tolist()
self._display_update(buf_black, buf_red)
self._display_fini()
示例13: matrix_visualization
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def matrix_visualization(matrix,title=None):
""" Visualize 2D matrices like spectrograms or feature maps.
"""
plt.figure()
plt.imshow(np.flipud(matrix.T),interpolation=None)
plt.colorbar()
if title!=None:
plt.title(title)
plt.show()
示例14: readPFM
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def readPFM(file):
file = open(file, 'rb')
color = None
width = None
height = None
scale = None
endian = None
header = file.readline().rstrip()
if header == 'PF':
color = True
elif header == 'Pf':
color = False
else:
raise Exception('Not a PFM file.')
dim_match = re.match(r'^(\d+)\s(\d+)\s$', file.readline())
if dim_match:
width, height = map(int, dim_match.groups())
else:
raise Exception('Malformed PFM header.')
scale = float(file.readline().rstrip())
if scale < 0: # little-endian
endian = '<'
scale = -scale
else:
endian = '>' # big-endian
data = np.fromfile(file, endian + 'f')
shape = (height, width, 3) if color else (height, width)
data = np.reshape(data, shape)
data = np.flipud(data)
return data, scale
示例15: readPFM
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import flipud [as 别名]
def readPFM(file):
file = open(file, 'rb')
color = None
width = None
height = None
scale = None
endian = None
header = file.readline().rstrip()
encode_type = chardet.detect(header)
header = header.decode(encode_type['encoding'])
if header == 'PF':
color = True
elif header == 'Pf':
color = False
else:
raise Exception('Not a PFM file.')
dim_match = re.match(r'^(\d+)\s(\d+)\s$', file.readline().decode(encode_type['encoding']))
if dim_match:
width, height = map(int, dim_match.groups())
else:
raise Exception('Malformed PFM header.')
scale = float(file.readline().rstrip().decode(encode_type['encoding']))
if scale < 0: # little-endian
endian = '<'
scale = -scale
else:
endian = '>' # big-endian
data = np.fromfile(file, endian + 'f')
shape = (height, width, 3) if color else (height, width)
data = np.reshape(data, shape)
data = np.flipud(data)
return data, scale