[Numpy-discussion] discussion about array.resize() -- compare to numarray
Sebastian Haase
seb.haase at gmx.net
Fri Jan 5 16:00:50 CST 2007
On 1/5/07, Russell E Owen <rowen at cesmail.net> wrote:
> In article
> <bc657ead0701041629i4f9e2fddg26efac5256bde3cb at mail.gmail.com>,
> "Sebastian Haase" <seb.haase at gmx.net> wrote:
>
> > On 1/4/07, Sebastian Haase <haase at msg.ucsf.edu> wrote:
> > <snip>
> > > >>> N.__version__
> > > '1.0.2.dev3487'
> > >
> > > in any case: inside the script it somehow generated a nan --- is
> > > there a bug in numpy !?
> >
> > No bug here ! see below !
> >
> > > I remember that there was some discussion about resize !?
> > > What should I add to the Scipy Wiki numarray page about this ?
> > > ( http://www.scipy.org/Converting_from_numarray )
> > >
> >
> > OK - the reference problem in my interactive shell came from the
> > implicit '_' variable that always references the last result. But
> > maybe even more worry some for the converting from numarray is this:
> > >>> a = N.array([5])
> > >>> 999 # to kill '_' - reference
> > 999
> > >>> a.resize(2)
> > >>> a
> > [5 0]
> >
> > in numarray you would get
> > >>> a = na.array([5])
> > >>> a.resize(2)
> > [5 5]
> > >>> a
> > [5 5]
> >
> > !! why is numpy filling with 0s and numarray repeats (cycles I think
> > is more what it does !) the last element(s) ??
> >
> > How did numeric do this ?
>
> Here's what I get for Numeric 24.2:
>
> >>> import Numeric as N
> >>> a = N.array([5])
> >>> a
> array([5])
> >>> a.resize(2)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: cannot resize an array that has been referenced or is
> referencing
> another array in this way. Use the resize function.
> >>> N.resize(a, 2)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-pac
> kages/Numeric/Numeric.py", line 422, in resize
> total_size = multiply.reduce(new_shape)
> ValueError: dimension not in array
> >>> N.resize(a, [2])
> array([5, 5])
>
Thanks for testing -- to be complete I will append my tests for
numarray and numpy.
I would consider the different result of function vs. method a bug !!
Please comment , Sebastian.
>>> import numarray as na
>>> import numpy as N
>>> a = na.array([5])
>>> a.resize(2)
[5 5]
>>> a
[5 5]
>>> a = na.array([5])
>>> na.resize(a,2)
[5 5]
>>> a
[5]
>>> a = N.array([5])
>>> a.resize(2)
>>> a
[5 0]
>>> a = N.array([5])
>>> N.resize(a, 2)
[5 5]
>>> a
[5]
### Note: [5 5] vs. [5 0] !!!
More information about the Numpy-discussion
mailing list