![](https://secure.gravatar.com/avatar/78979acd7771e6b6ba55a8923b5793f3.jpg?s=120&d=mm&r=g)
Hi, the documentation for dot says that a value error is raised if: If the last dimension of a is not the same size as the second-to-last dimension of b. (http://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.htm) This doesn't appear to be the case:
a = array([[1,2],[3,4]]) b = array([1,2]) dot(a,b) array([5,11])
I can see *how* 5,11 is obtained, but it seems this should have raised a ValueError since the 2 != 1. So the actual code must do something more involved. When I think about broadcasting, it seems that maybe b should have been broadcasted to: --> array([[1,2],[1,2]]) and then the multiplication done as normal (but this would give a 2x2 result). Can someone explain this to me?
![](https://secure.gravatar.com/avatar/78979acd7771e6b6ba55a8923b5793f3.jpg?s=120&d=mm&r=g)
Oh. b.shape = (2,). So I suppose the second to last dimension is, in fact, the last dimension...and 2 == 2. nvm On Fri, Aug 7, 2009 at 2:19 PM, T J<tjhnson@gmail.com> wrote:
Hi, the documentation for dot says that a value error is raised if:
If the last dimension of a is not the same size as the second-to-last dimension of b.
(http://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.htm)
This doesn't appear to be the case:
a = array([[1,2],[3,4]]) b = array([1,2]) dot(a,b) array([5,11])
I can see *how* 5,11 is obtained, but it seems this should have raised a ValueError since the 2 != 1. So the actual code must do something more involved. When I think about broadcasting, it seems that maybe b should have been broadcasted to:
--> array([[1,2],[1,2]])
and then the multiplication done as normal (but this would give a 2x2 result).
Can someone explain this to me?
![](https://secure.gravatar.com/avatar/96dd777e397ab128fedab46af97a3a4a.jpg?s=120&d=mm&r=g)
On Fri, Aug 7, 2009 at 3:24 PM, T J <tjhnson@gmail.com> wrote:
Oh. b.shape = (2,). So I suppose the second to last dimension is, in fact, the last dimension...and 2 == 2.
nvm
On Fri, Aug 7, 2009 at 2:19 PM, T J<tjhnson@gmail.com> wrote:
Hi, the documentation for dot says that a value error is raised if:
If the last dimension of a is not the same size as the second-to-last dimension of b.
(http://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.htm)
This doesn't appear to be the case:
a = array([[1,2],[3,4]]) b = array([1,2]) dot(a,b) array([5,11])
I can see *how* 5,11 is obtained, but it seems this should have raised a ValueError since the 2 != 1. So the actual code must do something more involved. When I think about broadcasting, it seems that maybe b should have been broadcasted to:
--> array([[1,2],[1,2]])
and then the multiplication done as normal (but this would give a 2x2 result).
Can someone explain this to me?
It looks like a bug in the documentation. Vectors, i.e., 1D arrays, are multiplied as if they were column/row vectors depending on what side of the product they occur. Chuck
participants (2)
-
Charles R Harris
-
T J