Python Forum
x and y must have same first dimension, but have shapes (1,) and (50,)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
x and y must have same first dimension, but have shapes (1,) and (50,)
#1
Hey there python community, after successfully plotting a graph, when it comes to plotting the frontier of it, I get this message:
ValueError: x and y must have same first dimension, but have shapes (1,) and (50,)
This is the graph:
plt.figure(figsize=(22,7))
plt.scatter(expectedVolatility,expectedReturn,c=sharpeRatio)
plt.xlabel('expected volatility')
plt.ylabel('expected log returns')
plt.colorbar(label='sharpe ratio')
plt.scatter(expectedVolatility[maxIndex],expectedReturn[maxIndex],c='red')
plt.plot(volatility_opt,returns, '--')
plt.show()
I know this kind of error is very common and in my humble opinion probably it arises from here:
returns = np.linspace(0, 1.50, num= 50, endpoint=True, retstep=False, dtype=None, axis=0)
volatility_opt = []
and the output is
 volatility_opt

[10.194341397342678] 
as the volatility_opt shouldn't be obviously just one value. I can't find yet precisely the origin, where could it be?
Reply


Messages In This Thread
x and y must have same first dimension, but have shapes (1,) and (50,) - by asja2010 - Jan-11-2023, 03:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I design shapes on a curve in python? mervea 2 922 Sep-14-2023, 01:04 PM
Last Post: Pedroski55
  Array dimension don't match asja2010 0 1,207 Feb-23-2023, 04:22 PM
Last Post: asja2010
  Shapes in Video finndude 0 768 Oct-07-2022, 03:30 PM
Last Post: finndude
  Shapes over video in tkinter finndude 1 1,037 Oct-04-2022, 06:14 PM
Last Post: deanhystad
  operands could not be broadcast together with shapes (337,451) (225,301) kevinabbot 0 1,637 Dec-14-2021, 04:02 PM
Last Post: kevinabbot
  Strange error ValueError: dimension mismatch Anldra12 0 2,059 Aug-17-2021, 07:54 AM
Last Post: Anldra12
  ValueError: dimension mismatch Anldra12 0 3,525 Jul-17-2021, 04:46 PM
Last Post: Anldra12
  ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, hobbyist 17 152,957 Mar-22-2021, 10:27 AM
Last Post: hobbyist
  Error When Plotting ValueError: x and y must have same first dimension JoeDainton123 1 9,239 Oct-04-2020, 12:58 PM
Last Post: scidam
  Wrong dimension for my plot Jemeronimo 1 2,083 Apr-25-2019, 06:19 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020