Skip to content
Advertisement

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

I want to find maxima and minima from a list, but after running my program, terminal shows error like “ValueError: x and y must have same first dimension, but have shapes (1, 2) and (2,),”. How to fix this problem?

Code:

JavaScript

Advertisement

Answer

As you can see in the documentation, maxima and minima are not 1 dimensional arrays but tuples of ndarrays

JavaScript

let’s check

JavaScript

gives

JavaScript

and

JavaScript

gives

JavaScript

Since you need the first element only of the tuple, you can do

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement