[Numpy-discussion] Re: reshape and ravel methods of arrays now return views or raise error
Charles R Harris
charlesr.harris at gmail.com
Tue Mar 28 22:49:05 CST 2006
On 3/28/06, Robert Kern <robert.kern at gmail.com> wrote:
> Charles R Harris wrote:
> > On 3/28/06, *Zachary Pincus* <zpincus at stanford.edu
> > <mailto:zpincus at stanford.edu>> wrote:
> > Let me give a more concrete example, pulled from some code I was
> > actually using.
> > The code is obviously a bit flawed, but it worked fine with numpy up
> > until today. Now it breaks when a and b aren't both c-strided:
> > def distance_squared(a, b):
> > return numpy.sum( (a.ravel() - b.ravel())**2 )
> > def distance_squared(a,b)
> > return ((a - b)**2).sum()
> > The function should probably throw an error if a and b don't have the
> > same shape and order and now it does.
> Does it?
> In : def distance_squared(a, b):
> ....: return ((a - b) ** 2).sum()
> In : distance_squared(arange(5), arange(3)[:,newaxis])
> Out: 55
Oops! Guess there should be a test for shape equality in there somewhere.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion