def subplot(plt, (Y, X), (sz_y, sz_x) = (10, 10)): 在 Python 中抛出无效语法 3
def subplot(plt, (Y, X), (sz_y, sz_x) = (10, 10)): throws invalid syntax in Python 3
我正在尝试 运行 最初为 Python 2 编写的代码用于 Python 3。
代码块是:
def draw_bbox(plt, ax, rois, fill=False, linewidth=2, edgecolor=[1.0, 0.0, 0.0], **kwargs):
for i in range(rois.shape[0]):
roi = rois[i,:].astype(np.int)
ax.add_patch(plt.Rectangle((roi[0], roi[1]),
roi[2] - roi[0], roi[3] - roi[1],
fill=False, linewidth=linewidth, edgecolor=edgecolor, **kwargs))
def subplot(plt, (Y, X), (sz_y, sz_x) = (10, 10)):
plt.rcParams['figure.figsize'] = (X*sz_x, Y*sz_y)
fig, axes = plt.subplots(Y, X)
return fig, axes
我收到的错误是:
File "<ipython-input-7-9e2eb5f0d3ab>", line 8
def subplot(plt, (Y, X), (sz_y, sz_x) = (10, 10)):
^
SyntaxError: invalid syntax
我该如何解决这个问题?代码来自这个 repo:https://github.com/s-gupta/v-coco/blob/master/V-COCO.ipynb
您不能将集合作为参数放在用户定义函数的参数中。您可以将 X 和 Y 分成两个不同的参数,例如:
def subplot(plt, Y, X, (sz_y, sz_x) = (10, 10)):
或者您可以像 python3
中那样指定一个元组
def subplot(plt, xy: set, (sz_y, sz_x) = (10, 10)):
重写此函数的方法如下:
def subplot(plt, yx, sz = (10, 10)):
(Y, X) = yx
(sz_y, sz_x) = sz
plt.rcParams['figure.figsize'] = (X*sz_x, Y*sz_y)
fig, axes = plt.subplots(Y, X)
return fig, axes
我正在尝试 运行 最初为 Python 2 编写的代码用于 Python 3。 代码块是:
def draw_bbox(plt, ax, rois, fill=False, linewidth=2, edgecolor=[1.0, 0.0, 0.0], **kwargs):
for i in range(rois.shape[0]):
roi = rois[i,:].astype(np.int)
ax.add_patch(plt.Rectangle((roi[0], roi[1]),
roi[2] - roi[0], roi[3] - roi[1],
fill=False, linewidth=linewidth, edgecolor=edgecolor, **kwargs))
def subplot(plt, (Y, X), (sz_y, sz_x) = (10, 10)):
plt.rcParams['figure.figsize'] = (X*sz_x, Y*sz_y)
fig, axes = plt.subplots(Y, X)
return fig, axes
我收到的错误是:
File "<ipython-input-7-9e2eb5f0d3ab>", line 8
def subplot(plt, (Y, X), (sz_y, sz_x) = (10, 10)):
^
SyntaxError: invalid syntax
我该如何解决这个问题?代码来自这个 repo:https://github.com/s-gupta/v-coco/blob/master/V-COCO.ipynb
您不能将集合作为参数放在用户定义函数的参数中。您可以将 X 和 Y 分成两个不同的参数,例如:
def subplot(plt, Y, X, (sz_y, sz_x) = (10, 10)):
或者您可以像 python3
中那样指定一个元组def subplot(plt, xy: set, (sz_y, sz_x) = (10, 10)):
重写此函数的方法如下:
def subplot(plt, yx, sz = (10, 10)):
(Y, X) = yx
(sz_y, sz_x) = sz
plt.rcParams['figure.figsize'] = (X*sz_x, Y*sz_y)
fig, axes = plt.subplots(Y, X)
return fig, axes