[Numpy-discussion] reshape and ravel methods of arrays now return views or raise error

Charles R Harris charlesr.harris at gmail.com
Tue Mar 28 22:01:03 CST 2006

On 3/28/06, Zachary Pincus <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. I note that your original function was
written for the old functional sum and attempts to be efficient. The new
Numpy sum method make it much easier to do what you want. Thanks, Travis.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060328/87fe20d3/attachment.html 

More information about the Numpy-discussion mailing list