import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 100, 50)
y = np.random.randn(1, 50)
plt.plot(x, y)
如上代码报错为:“ValueError: x and y must have same first dimension, but have shapes (50, ) and (1, 50).”。正确代码如下:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 100, 50)
y = np.random.randn(1, 50).squeeze()
plt.plot(x, y)
如果您觉得我的文章对您有所帮助,欢迎扫码进行赞赏!