回溯错误
Traceback (most recent call last):
File "C:\Users\trial2\trial.py", line 55, in <module>
image_stack(image)
File "C:\Users\trial2\trial.py", line 41, in image_stack
transposed_axes = np.transpose(img, axes=concat)
File "<__array_function__ internals>", line 5, in transpose
File "C:\Users\trial2\venv\lib\site-packages\numpy\core\fromnumeric.py", line 660, in transpose
return _wrapfunc(a, 'transpose', axes)
File "C:\Users\trial2\venv\lib\site-packages\numpy\core\fromnumeric.py", line 57, in _wrapfunc
return bound(*args, **kwds)
ValueError: axes don't match array
如果这有助于解决问题,那么回溯错误也存在 我需要计算作为参数输入到函数中的图像的新转置轴。该函数获取图像的形状,然后计算图像的转置轴。将图像阵列转置到新轴时出现问题。我不明白为什么它不起作用。我是否需要将concat变量转换为元组以使其正常工作,还是其他原因导致了该问题
def image_stack(image):
img_shape = cv2.imread(image).shape
img = np.asarray(img_shape)
print(type(img))
n = len(img)
val_1 = list(range(1, n - 1, 2))
val_2 = list(range(0, n - 1, 2))
print(img)
if n % 2 == 0:
y_ax = val_1
x_ax = val_2
axes = (y_ax, x_ax, [n-1])
else:
y_ax = val_2
x_ax = val_1
axes = (y_ax, x_ax, [n - 1])
print(type(axes))
concat = np.concatenate(axes)
print(concat)
if type(axes) == tuple:
transposed_axes = np.transpose(img, axes=concat)
print(transposed_axes)
image = 'C:\\trial_images\\9.jpg'
image_stack(image)
轴参数的类型无关紧要:
但是,如果我提供的值多于
arr
的维度,我会得到您的错误:我期望[0,1,2]和2d
arr
也会有同样的结果希望这能让您了解如何自己调试问题。启动一个交互式会话并尝试一些替代方案
相关问题 更多 >
编程相关推荐