Home > Mobile >  numpy ValueError: shapes not alligned
numpy ValueError: shapes not alligned

Time:12-07

Super simple question here, I am getting this error code:

shapes (30,) and (1,30) not aligned: 30 (dim 0) != 1 (dim 0)

how would I easily refactor the second array to be the same as the first array, or vice versa.
Example:

x output is: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
y output is: [[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]]

x shape is (30,) y shape is (1,30)

anything helps.
I could use a for loop but that seems so counterintuitive, just looking for a better method.
Thanks

CodePudding user response:

You can use

y = y.reshape(-1)

or

y = np.squeeze(y)

CodePudding user response:

The numpy reshape() function would be very helpful for this (https://numpy.org/doc/stable/reference/generated/numpy.reshape.html).

  • Related