ValueError Traceback (most recent call last) <ipython-input-64-56a70bbb0400> in <module> 7 plt.title('2020级外国语学院各班级总学时') 8 plt.subplot(222) ----> 9 sns.barplot(x=bj_sp_new_sort1.index,y=bj_sp_new_sort1.学时) 10 plt.xticks(rotation=90) 11 plt.title('2020级食品与工程学院各班级总学时') D:\Users\h\anaconda3\lib\site-packages\seaborn\_decorators.py in inner_f(*args, **kwargs) 44 ) 45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)}) ---> 46 return f(**kwargs) 47 return inner_f 48 D:\Users\h\anaconda3\lib\site-packages\seaborn\categorical.py in barplot(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, seed, orient, color, palette, saturation, errcolor, errwidth, capsize, dodge, ax, **kwargs) 3177 ): 3178 -> 3179 plotter = _BarPlotter(x, y, hue, data, order, hue_order, 3180 estimator, ci, n_boot, units, seed, 3181 orient, color, palette, saturation, D:\Users\h\anaconda3\lib\site-packages\seaborn\categorical.py in __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, seed, orient, color, palette, saturation, errcolor, errwidth, capsize, dodge) 1584 self.establish_variables(x, y, hue, data, orient, 1585 order, hue_order, units) -> 1586 self.establish_colors(color, palette, saturation) 1587 self.estimate_statistic(estimator, ci, n_boot, seed) 1588 D:\Users\h\anaconda3\lib\site-packages\seaborn\categorical.py in establish_colors(self, color, palette, saturation) 317 # Determine the gray color to use for the lines framing the plot 318 light_vals = [colorsys.rgb_to_hls(*c)[1] for c in rgb_colors] --> 319 lum = min(light_vals) * .6 320 gray = mpl.colors.rgb2hex((lum, lum, lum)) 321 ValueError: min() arg is an empty sequence
时间: 2024-04-03 15:35:13 浏览: 241
根据你提供的错误信息,可以看出是在运行 `sns.barplot(x=bj_sp_new_sort1.index,y=bj_sp_new_sort1.学时)` 这一行代码时出现了 ValueError,报错信息是 `min() arg is an empty sequence`,意思是 `min()` 函数的参数是一个空序列,无法进行计算。这说明可能是 `bj_sp_new_sort1` 这个 DataFrame 中的数据为空,导致无法绘制柱状图。你可以检查一下 `bj_sp_new_sort1` 中是否存在空值或者缺失值。
相关问题
ValueError Traceback (most recent call last) <ipython-input-22-000300cc57e6> in <module> ----> 1 QR(M) <ipython-input-21-01e8d556429b> in QR(A) 6 a = R[j:, j] 7 v = np.zeros(m) ----> 8 v[j:] = a + np.sign(a[0]) * np.linalg.norm(a) * np.eye(m)[j:] 9 v = v / np.linalg.norm(v) 10 H = np.eye(m) - 2 * np.outer(v, v) ValueError: could not broadcast input array from shape (10,10) into shape (10,)会报错
这个错误是因为在计算 `coeff_matrix` 时,使用了未定义的变量 `x`。可以将 `x` 定义为 `sp.symbols('a1:11')`,如下所示:
```
def QR(A):
m, n = A.shape
Q = np.eye(m)
R = A.copy()
for j in range(min(m, n)):
a = R[j:, j]
v = np.zeros(m)
v[j:] = a + np.sign(a[0]) * np.linalg.norm(a) * np.eye(m)[j:]
v = v / np.linalg.norm(v)
H = np.eye(m) - 2 * np.outer(v, v)
Q = Q @ H
R = H @ R
x = sp.symbols('a1:11')
coeff_matrix = sp.Matrix(np.zeros((10, 10)))
for i in range(10):
for j in range(10):
coeff_matrix[i, j] = sp.Matrix(x[i]).coeff(sp.Symbol('a{}'.format(j + 1)))
return(coeff_matrix)
```
这里定义 `x = sp.symbols('a1:11')`,并使用 `sp.Symbol('a{}'.format(j + 1))` 来获取符号变量 `a1` 至 `a10`。
ValueError Traceback (most recent call last) <ipython-input-20-000300cc57e6> in <module> ----> 1 QR(M) <ipython-input-19-490e012c78fb> in QR(A) 6 a = R[j:, j] 7 v = np.zeros(m) ----> 8 v[j:] = a + np.sign(a[0]) * np.linalg.norm(a) * np.eye(1, m, j) 9 v = v / np.linalg.norm(v) 10 H = np.eye(m) - 2 * np.outer(v, v) ValueError: operands could not be broadcast together with shapes (9,) (1,10) 会报这个错
这个错误是因为 `np.eye(1, m, j)` 返回的是一个形状为 `(1, m)` 的矩阵,而 `a` 是一个形状为 `(9,)` 的向量,无法直接相加。可以将 `np.eye(1, m, j)` 改为 `np.eye(m)[j:]`,如下所示:
```
def QR(A):
m, n = A.shape
Q = np.eye(m)
R = A.copy()
for j in range(min(m, n)):
a = R[j:, j]
v = np.zeros(m)
v[j:] = a + np.sign(a[0]) * np.linalg.norm(a) * np.eye(m)[j:]
v = v / np.linalg.norm(v)
H = np.eye(m) - 2 * np.outer(v, v)
Q = Q @ H
R = H @ R
coeff_matrix = sp.Matrix(np.zeros((10, 10)))
for i in range(10):
for j in range(10):
coeff_matrix[i, j] = sp.Matrix(x[i]).coeff(sp.Symbol('a{}'.format(j + 1)))
return(coeff_matrix)
```
这里使用 `np.eye(m)[j:]` 来获取第 `j` 行及其之后的单位矩阵。
阅读全文