[NumPy-Tickets] [NumPy] #2032: cross doesn't broadcast correctly

NumPy Trac numpy-tickets@scipy....
Fri Jan 27 15:29:12 CST 2012


#2032: cross doesn't broadcast correctly
--------------------+-------------------------------------------------------
 Reporter:  irving  |       Owner:  somebody   
     Type:  defect  |      Status:  new        
 Priority:  normal  |   Milestone:  Unscheduled
Component:  Other   |     Version:  1.6.1      
 Keywords:          |  
--------------------+-------------------------------------------------------

Comment(by irving):

 I haven't analyzed numpy.cross, because it's somewhat complicated, but
 here's a simpler routine which works at least in my case:

     def cross(u,v):
       # The numpy version doesn't always broadcast correctly, so we roll
 our own cross product routine.
       # Unfortunately, it's impossible to make 1D/2D cross products work
 correctly together with
       # broadcasting, so stick to 3D for now.
       assert u.shape[-1]==v.shape[-1]==3
       uv = empty(broadcast(u,v).shape)
       u0,u1,u2 = u[...,0],u[...,1],u[...,2]
       v0,v1,v2 = v[...,0],v[...,1],v[...,2]
       uv[...,0] = u1*v2-u2*v1
       uv[...,1] = u2*v0-u0*v2
       uv[...,2] = u0*v1-u1*v0
       return uv

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/2032#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list