1

Tengo este código

xfit = np.linspace(-1, 3.5)
plt.scatter(X[:, 0], X[:, 1], c=y, s=50, cmap='autumn')
plt.plot([0.6], [2,1], 'x', color='red', markeredgewidth=2, markersize=10)

for m, b in [(1, 0.70), (0.5, 1.6), (-0.2, 2.9)]:
    plt.plot(xfit, m * xfit + b, '-k')

plt.xlim(-1, 3.5);

Y me tira este error

ValueError: x and y must have same first dimension, but have shapes (1,) and (2,)

1
  • 1
    y cual es la matriz? o el objeto numpy, que estas tratando de hacer?, por favor añade mas detalles a tu pregunta
    – Christian
    el 29 may. 2021 a las 1:25

1 respuesta 1

1

El error en la línea plt.scatter se puede explicar simplemente con el siguiente ejemplo:

x = [1,] # dimension == 1
y = [1, 4] # dimension == 2
plt.plot(x, y)

ValueError: x and y must have same first dimension, but have shapes (1,) and (2,)

Mira lo que te da:

print(X[:, 0])
print(X[:, 1])

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.