[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
Robert,
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 [55]: def distance_squared(a, b):
> ....: return ((a - b) ** 2).sum()
> ....:
>
> In [56]: distance_squared(arange(5), arange(3)[:,newaxis])
> Out[56]: 55
Oops! Guess there should be a test for shape equality in there somewhere.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060328/6742b771/attachment-0001.html
More information about the Numpy-discussion
mailing list