[PYTHON MATRIX-SIG] Re: NumPy in Python 1.4
David Ascher
da@maigret.cog.brown.edu
Mon, 21 Oct 1996 15:53:06 -0400
Geoffrey Furnish wrote:
>
> I am working with Numerical Python extension 1.0a2 in a Python 1.4b3
> context. Lots of code I wrote previously under Python 1.3 and
> whatever version of NumPy it was that went wtih that, is now broken.
Yes, we know. It's because of the pesky little 'a' in 1.0a2 -- it is an
alpha release, and we've been discussing just these issues on the
matrix-sig for months.
> I have been in the habit of instantiating my arrays with the "zeros"
> thing. I used to say, for example:
>
> x = zeros(100)
>
> to get an array of 100 zero's. Well, in the new version, this still
> gives 100 zero's, but ... now they're integers, they used to be
> doubles. This change in the type returned by this function broke
> skads of code. I have had to change this to:
>
> x = zeros(100,'d')
>
> which I can live with, but I /much/ prefered the prior behavior. IMO,
> if you're gonna have a "default" number type, it should be float, not
> int. Converting to requiring the type specifier puts them on equal
> footing, but I like the defaultability--if it defaults to double, not
> int.
The reasoning (as I recall it) was that in all other methods, the array
type created corresponds to the smallest type which can represent all of
the elements. Since 0 and 1 can be represented accurately as integers,
that's what zeros() and ones() returns.
Note that the recommended typecodes are now Int, Float, etc.:
x = zeros(100, Float)
> Secondly, instantiating 2-d arrays has changed. I used to be able to
> do:
>
> z = zeros(XPTS,YPTS)
>
> Now I have to do:
>
> z = reshape( zeros( XPTS*YPTS, 'd' ), (XPTS, YPTS) )
>
> Curiously, the obvious:
>
> z = zeros( (XPTS,YPTS), 'd' )
>
> did not work on my Linux box, forcing me to use the reshape business
> exhibited above. I could not reproduce the same failure on my HP/UX
> box at work this morning, even though the same versions of Python and
> NumPy are involved.
>>> zeros((4,4), Float)
0. 0. 0. 0.
0. 0. 0. 0.
0. 0. 0. 0.
0. 0. 0. 0.
This works at least on my machines with the latest alpha release. If
you could try this with the 1.0a5 release and let us know the results,
that'd be great.
> Finally, I used to be able to do:
>
> zmin = min(zz.reshape())
> zmax = max(zz.reshape())
>
> where zz was a 2-d array, but that syntax isn't accepted now, and so
> I've been driven to:
>
> zmin = min(min(zz))
> zmax = max(max(zz))
>
> Again, I prefered the former. What I would most like is for min(x)
> applied to an N-d x, to return the single minimum value, not just an
> N-1-d set of minimum values. Similarly for other reduction operations
> like max.
I don't have an argument as to why this was chosen over the old version,
but note that you can do:
zmin = min(ravel(zz))
I am in the process of updating the tutorial to NumPy to document these
changes from the early alpha releases.
I for one am sorry that you seem frustrated with NumPy in some respects
-- it is however inevitable when dealing with an alpha release -- they
are released just to iron out what the best interface is. I'd recommend
that you check out the 1.0a5 release
(http://www.sls.lcs.mit.edu/~jjh/numpy) and make comments before it goes
beta (and the interface is frozen).
--david ascher [just a documenter, not the author]
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================