+ 1

How do I add these two numpy arrays [1,2,3]+[3,2]?

21st Mar 2019, 7:11 PM
Domenico Casanica
Domenico Casanica - avatar
3 ответов
+ 4
They are different shapes so you cannot add them like this. If you reshape the first one to be 3x1 instead of 1x3 then it works. https://code.sololearn.com/cLw3667wlEje/?ref=app
21st Mar 2019, 9:34 PM
Tibor Santa
Tibor Santa - avatar
+ 4
Check the numpy documentation for matrix addition. If they are not the same shape, then they must be 'broadcastable' to a common shape. Practically they need to share the dimension along which you add them. https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.add.html
21st Mar 2019, 9:46 PM
Tibor Santa
Tibor Santa - avatar
0
Why reshape the first array and not the second?
21st Mar 2019, 9:41 PM
Domenico Casanica
Domenico Casanica - avatar