0

I was trying to multiply two Numpy array but I am getting broadcasting related error-

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-124-6e9219ae5e45> in <module>
----> 1 d=B*C.reshape(-1,1)

ValueError: operands could not be broadcast together with shapes (3,5,7) (3,1) 

my arrays are-

B=np.random.rand(5,7,3).T.swapaxes(2,1)
C=np.linspace(1,5,3)
d=B*C.reshape(-1,1)

Can you please explain what kind of error is this and what I am supposed to do? Thank you

wjandrea
  • 28,235
  • 9
  • 60
  • 81

1 Answers1

0

You can try to changing the shape of your C array from (3,1) to (3, 1, 1).

B=np.random.rand(5,7,3).T.swapaxes(2,1)
C=np.linspace(1,5,3)
d=B*C.reshape(-1,1, 1)
Vishal Singh
  • 131
  • 1
  • 5