Python ValueError in broadcasting although right shapes

22 Views Asked by At

I have a problem in a bigger python project. This ist the code I'm trying to implement. I'm trying to find out in which interval of a0 the points in a lie (there will be a lot more points in the problem I'm trying to solve, but to figure out how it works I tried it with a smaller number of points. So solving it by manipulating it "point per point" will not work for me!)

len0 = 4
a0 = np.linspace(-1, 1, len0)
a10 = np.reshape(a0, (1, len0))

len1 = 8
a = np.linspace(-1, 1, len1)
a1 = np.reshape(a, (len1, 1))

check = ((a1\<a10\[1:\]) & (a1\>=a10\[:-1\]))

I get the error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[25], line 9
      6 a = np.linspace(-1, 1, len1)
      7 a1 = np.reshape(a, (len1, 1))
----> 9 check = ((a1<a10[1:]) & (a1>=a10[:-1]))
     10 check

ValueError: operands could not be broadcast together with shapes (8,1) (0,4) 

Although I specifically reshaped them to be (8,1) and (1,4) (and if I test them with .shape the result is (8,1) and (1,4)). Any idea where the problem is? Thanks a lot!

0

There are 0 best solutions below